PUBLIC ssize espRenderConfig(HttpConn *conn) { cchar *config; if ((config = getClientConfig(conn)) != 0) { return renderString(config); } return 0; }
int main(int argc, char **argv) { struct sigaction handler; handler.sa_sigaction = signalHandler; handler.sa_flags = SA_SIGINFO; sigaction(SIGINT, &handler, NULL); sigaction(SIGPIPE, &handler, NULL); sigaction(SIGTERM, &handler, NULL); string ip = "localhost"; int port = 5000; string tracker_ip = "127.0.0.1"; int tracker_port = 7500; storage_directory = "/home/deepthought/sandbox/p2pvideo/files"; char *tip, *dir, *cip; int bsize; getClientConfig(&tip, &tracker_port, &cip, &clients_port, &streaming_port, &dir, &bsize, &cache_size); tracker_ip = tip; ip = cip; storage_directory = dir; if (argc == 5) { ip = argv[1]; port = atoi(argv[2]); storage_directory = argv[3]; streaming_port = atoi(argv[4]); cout<<"storage directory is "<<storage_directory<<endl; clients_port = port; /* ip += ":"; ip += argv[2]; */ cout<<ip<<endl; } /* vector<bool> tmap; int tnum = 5; for (int i = 0; i < tnum; i++) { bool val = (i % 2 == 0); tmap.push_back(val); } BlockMap tblock(tmap); //tblock.print(); int size; char *data = tblock.serialize(size); BlockMap dblock; dblock.deserialize(data, size); //dblock.print(); string filename = "testurl1234567890"; File tfile(filename, tmap); //tfile.print(); data = tfile.serialize(size); File dfile; dfile.deserialize(data, size); //dfile.print(); Client tclient(ip, port, "/tmp"); tclient.addFile(tfile); //tclient.print(); cout<<endl<<endl; Client dclient; int size2; char *data2 = tclient.serialize(size2); //dclient.deserialize(data2, size2); //dclient.print(); int sockfd = connectToTracker(tracker_ip, tracker_port); if (sockfd != -1) { cout<<"Connected to tracker"<<endl; } //registerWithTracker(sockfd, tclient); for (int i = 0; i < tnum; i++) { tmap[i] = true; } int file_idx = tclient.getFileIdxByURL(filename); //tclient.updateFile(file_idx, tmap); //updateOnTracker(sockfd, tclient); */ pthread_rwlock_init(&client_mutex, NULL); Client tmpc(ip, clients_port, storage_directory); c = tmpc; c.connectToTracker(tracker_ip, tracker_port); c.registerWithTracker(); c.queryTracker(); c.client_mutex = &client_mutex; pthread_t streamer, queryThread, updateThread, statsThread; pthread_create(&streamer, NULL, handleStreaming, NULL); pthread_create(&queryThread, NULL, handleQuery, NULL); pthread_create(&updateThread, NULL, handleUpdate, NULL); pthread_create(&statsThread, NULL, handleStats, NULL); clients_sockfd = bindToPort(ip, clients_port); if(clients_sockfd == -1) { cout << "Could not create a socket for incoming client connections" << endl; abort(); exit(1); } pthread_t client_threads[MAX_CLIENT_THREADS]; int thread_id = 0; while(listen(clients_sockfd, BACKLOG) == 0) { struct sockaddr_storage incoming; socklen_t incoming_sz = sizeof(incoming); long new_fd = accept(clients_sockfd, (struct sockaddr *)&incoming, &incoming_sz); if (new_fd == -1) { cout<<"peer accept failed with error: "<<strerror(errno)<<endl; exit(1); } else { if(pthread_create(&client_threads[thread_id], NULL, fileTransfer, (void *)new_fd)) { cout<<"Thread creating failed"<<endl; } else { thread_id++; } } } while(1); return 0; }