int main(int argc, char* argv[]) { int user_or_kernel; string nodeID; size_t nodeID_len; switch (argc) { case 2:{ /*By Default I assume blackadder is running in user space*/ nb_ba = NB_Blackadder::Instance(true); rv_or_implicit = 1; /*construct the nodeID from the second arg*/ nodeID = argv[1]; nodeID_len = nodeID.size(); break; } case 3:{ /*By Default I assume blackadder is running in user space*/ nb_ba = NB_Blackadder::Instance(true); rv_or_implicit = atoi(argv[1]); nodeID = argv[2]; nodeID_len = nodeID.size(); break; } case 4:{ user_or_kernel = atoi(argv[1]); if (user_or_kernel == 0) { nb_ba = NB_Blackadder::Instance(true); } else { nb_ba = NB_Blackadder::Instance(false); } rv_or_implicit = atoi(argv[2]); nodeID = argv[3]; nodeID_len = nodeID.size(); break; } default: cout << "Error: Wrong number of input arguments" << endl << "App Usage: sudo ./ping_subscriber <user_or_kernel> (Optional) 1|0 <rv_or_implicit> (Optional) 1|0 <pinged_node> NODE_NONZERO_DIGITS" << endl << "Defaults: user_or_kernel 1 rv_or_implicit 1" << endl << "E.g.: sudo ./ping_subscriber 244" << endl; break; } /*Set the callback function*/ nb_ba->setCallback(eventHandler); /***************************/ cout << "Process ID: " << getpid() << endl; id = string((PURSUIT_ID_LEN * 2) - nodeID_len, '0'); id += nodeID; prefix_id = string(PURSUIT_ID_LEN * 2, '0'); bin_id = hex_to_chararray(id); bin_prefix_id = hex_to_chararray(prefix_id); /*Server Sub to: AAAAAAAAAAAAAAAA/serverID to recieve ping requests from all clients for any sequence of pings*/ /*clients will publish requests in: AAAAAAAAAAAAAAAA/serverID/clientID/PingSequenceID*/ /*Server will later on make further subscription to AAAAAAAAAAAAAAAA/serverID/clientID to recieve ping requests*/ nb_ba->subscribe_scope(bin_id, bin_prefix_id, DOMAIN_LOCAL, NULL, 0); nb_ba->join(); nb_ba->disconnect(); delete nb_ba; cout << "exiting...." << endl; return 0; }
int main(int argc, char* argv[]) { srand(time(NULL)); string id; string prefix_id; string bin_id; string bin_prefix_id; Event ev; pthread_t event_listener; (void) signal(SIGINT, sigfun); if (argc > 1) { int user_or_kernel = atoi(argv[1]); if (user_or_kernel == 0) { ba = Blackadder::Instance(true); } else { ba = Blackadder::Instance(false); } } else { /*By Default I assume blackadder is running in user space*/ ba = Blackadder::Instance(true); } cout << "subscribing to the video catalogue information item" << endl; id = "0000000000000000"; prefix_id = "0000000000000000"; bin_id = hex_to_chararray(id); bin_prefix_id = hex_to_chararray(prefix_id); ba->subscribe_info(bin_id, bin_prefix_id, DOMAIN_LOCAL, NULL, 0); ba->getEvent(ev); if (ev.type == PUBLISHED_DATA) { if (ev.id.compare(bin_prefix_id + bin_id) == 0) { cout << "received Video Catalogue" << endl; ba->unsubscribe_info(bin_id, bin_prefix_id, DOMAIN_LOCAL, NULL, 0); string video_catalogue((char *) ev.data, ev.data_len); cout << video_catalogue << endl; cout << "Please select the video stream you want to join" << endl; cin >> video_stream; cout << "You selected to watch the stream with title " << video_stream << " ...soon it will be here :)" << endl; unsigned char *c_channel_id = (unsigned char *) malloc(256); /*publish the channel for this info*/ SHA1((const unsigned char *) video_stream.c_str(), video_stream.length(), c_channel_id); string channel_id = string((const char *) c_channel_id).substr(0, PURSUIT_ID_LEN); cout << "Subscribing to video channel with ID " << id + chararray_to_hex(channel_id) << endl; prefix_id = "0000000000000000"; bin_prefix_id = hex_to_chararray(prefix_id); ba->subscribe_info(channel_id, bin_prefix_id, DOMAIN_LOCAL, NULL, 0); } else {
int main(int argc, char* argv[]) { string id; string prefix_id; string bin_id; string bin_prefix_id; if (argc > 1) { int user_or_kernel = atoi(argv[1]); if (user_or_kernel == 0) { nb_ba = nb_blackadder::instance(true); } else { nb_ba = nb_blackadder::instance(false); } } else { /*By Default I assume blackadder is running in user space*/ nb_ba = nb_blackadder::instance(true); } /*Set the callback function*/ nb_ba->setCallback(eventHandler); /***************************/ cout << "Process ID: " << getpid() << endl; /*****************************publish root scope /0000000000000000 ************************************/ id = "1111111111111111"; prefix_id = string(); bin_id = hex_to_chararray(id); bin_prefix_id = hex_to_chararray(prefix_id); nb_ba->publish_scope(bin_id, bin_prefix_id, NODE_LOCAL, NULL, 0); id = "1111111111111111"; prefix_id = "1111111111111111"; bin_id = hex_to_chararray(id); bin_prefix_id = hex_to_chararray(prefix_id); nb_ba->publish_info(bin_id, bin_prefix_id, NODE_LOCAL, NULL, 0); nb_ba->join(); delete nb_ba; cerr << "exiting..." << endl; return 0; }
int main(int argc, char* argv[]) { (void) signal(SIGINT, sigfun); (void) signal(SIGTERM, termfun) ; if (argc == 1) { int user_or_kernel = atoi(argv[1]); if (user_or_kernel == 0) { ba = Blackadder::Instance(true); } else { ba = Blackadder::Instance(false); } } else { /*By Default I assume blackadder is running in user space*/ ba = Blackadder::Instance(true); } //cout << "Process ID: " << getpid() << endl; if(argc != 4) { cout<<"parameter error"<<endl ; return 0 ; } FILESIZE = atoi(argv[1]) ; CHUNKSIZE = atoi(argv[2]) ; SEGSIZE = atoi(argv[3]) ; cout<<"FILESIZE:"<<FILESIZE<<" CHUNKSIZE:"<<CHUNKSIZE<<" SEGSIZE:"<<SEGSIZE<<endl ; unsigned int file_num = 1 ; string bin_prefix_id ; string bin_id ; while(file_num <= FILESIZE) { string fileid ; char filename[10] ; sprintf(filename, "%X", file_num) ; fileid.insert(0, 2*PURSUIT_ID_LEN-strlen(filename), '0') ; fileid += filename ; string prefix_id ; bin_id = hex_to_chararray(fileid); bin_prefix_id = hex_to_chararray(prefix_id); ba->publish_scope(bin_id, bin_prefix_id, DOMAIN_LOCAL, NULL, 0); usleep(10) ; file_num++ ; } file_num = 1 ; while(file_num <= FILESIZE) { string fileid ; char filename[10] ; sprintf(filename, "%X", file_num) ; fileid.insert(0, 2*PURSUIT_ID_LEN-strlen(filename), '0') ; fileid += filename ; unsigned int chunk_num = 1 ; while(chunk_num <= CHUNKSIZE) { string chunkid ; char chunkname[10] ; sprintf(chunkname, "%X", chunk_num) ; chunkid.insert(0, 2*PURSUIT_ID_LEN - strlen(chunkname), '0') ; chunkid += chunkname ; bin_id = hex_to_chararray(chunkid) ; bin_prefix_id = hex_to_chararray(fileid) ; ba->publish_scope(bin_id, bin_prefix_id, DOMAIN_LOCAL, NULL, 0); usleep(1000) ; chunk_num++ ; } file_num++ ; } file_num = 1 ; while(file_num <= FILESIZE) { string fileid ; char filename[10] ; sprintf(filename, "%X", file_num) ; fileid.insert(0, 2*PURSUIT_ID_LEN-strlen(filename), '0') ; fileid += filename ; unsigned int chunk_num = 1 ; while(chunk_num <= CHUNKSIZE) { string chunkid ; char chunkname[10] ; sprintf(chunkname, "%X", chunk_num) ; chunkid.insert(0, 2*PURSUIT_ID_LEN - strlen(chunkname), '0') ; chunkid += chunkname ; unsigned int seg_num = 1 ; string file_chunk_id = fileid + chunkid ; while(seg_num <= SEGSIZE) { string segid ; char segname[10] ; sprintf(segname, "%X", seg_num) ; segid.insert(0, 2*PURSUIT_ID_LEN - strlen(segname), '0') ; segid += segname ; bin_id = hex_to_chararray(segid) ; bin_prefix_id = hex_to_chararray(file_chunk_id) ; ba->publish_info(bin_id, bin_prefix_id, DOMAIN_LOCAL, NULL, 0) ; usleep(1000) ; seg_num++ ; } chunk_num++ ; } file_num++ ; } cout<<"ready to sent"<<endl ; while (true) { Event ev; ba->getEvent(ev); switch (ev.type) { case SCOPE_PUBLISHED: cout << "SCOPE_PUBLISHED: " << chararray_to_hex(ev.id) << endl; break; case SCOPE_UNPUBLISHED: cout << "SCOPE_UNPUBLISHED: " << chararray_to_hex(ev.id) << endl; break; case CINC_REQ_DATA_PUB: data_sent_num++ ; cout << "CINC_REQ_DATA_PUB: " << chararray_to_hex(ev.id) << endl; ba->publish_data(PUBLISH_DATA, ev.id, IMPLICIT_RENDEZVOUS, ev.to_sub_FID._data, ev.fid_len, payload, payload_size); break; case CINC_PUSH_TO_CACHE: data_sent_num++ ; cout << "CINC_PUSH_TO_CACHE: " << chararray_to_hex(ev.id) << endl; ba->publish_data(ev.type, ev.id, IMPLICIT_RENDEZVOUS, ev.to_sub_FID._data, ev.fid_len, payload, payload_size); break ; case STOP_PUBLISH: cout << "STOP_PUBLISH: " << chararray_to_hex(ev.id) << endl; break ; case PUBLISHED_DATA: cout << "PUBLISHED_DATA: " << chararray_to_hex(ev.id) << endl; break ; } } sleep(5); free(payload); ba->disconnect(); delete ba; return 0; }
void eventHandler(Event *ev) { char * payload; int payload_size; switch (ev->type) { case SCOPE_PUBLISHED: /*rv_or_implicit =1 -> Clients publish their pings as: AAAAAAAAAAAAAAAA/serverID/clientID/PingSequenceID*/ /*Therefore Server need to subscribe to the child scope AAAAAAAAAAAAAAAA/serverID/clientID*/ published_scope_id = chararray_to_hex((string)ev->id); id = string(published_scope_id, (PURSUIT_ID_LEN * 2) * 2, PURSUIT_ID_LEN * 2); prefix_id = string(published_scope_id, 0, (PURSUIT_ID_LEN * 2) * 2); bin_id = hex_to_chararray(id); bin_prefix_id = hex_to_chararray(prefix_id); nb_ba->subscribe_scope(bin_id, bin_prefix_id, DOMAIN_LOCAL, NULL, 0); break; case PUBLISHED_DATA: no_pings = atoi((char *)ev->data); c_id = chararray_to_hex((string)ev->id); if ((no_pings < 1) & (rv_or_implicit == 0)) { /*rv_or_implicit = 0 -> firstping is publish_info under (SID/SID/RID) - (AAAAAAAAAAAAAAAA/clientID/serverID)*/ prefix_id = string(c_id, 0, PURSUIT_ID_LEN * 2) + string(c_id, (PURSUIT_ID_LEN * 2) * 2, PURSUIT_ID_LEN * 2); id = string(c_id, PURSUIT_ID_LEN * 2, PURSUIT_ID_LEN * 2); bin_prefix_id = hex_to_chararray(prefix_id); bin_id = hex_to_chararray(id); nb_ba->publish_info(bin_id, bin_prefix_id, DOMAIN_LOCAL, NULL, 0); } else if ((no_pings >= 1) & (rv_or_implicit == 0)) { /*rv_or_implicit = 0 -> subsequent pings are publish_data directly under (SID/SID/RID) - (AAAAAAAAAAAAAAAA/clientID/serverID)*/ /*No More RV involvement*/ prefix_id = string(c_id, 0, PURSUIT_ID_LEN * 2) + string(c_id, (PURSUIT_ID_LEN * 2) * 2, PURSUIT_ID_LEN * 2); bin_prefix_id = hex_to_chararray(prefix_id); id = string(c_id, PURSUIT_ID_LEN * 2, PURSUIT_ID_LEN * 2); bin_id = hex_to_chararray(id); payload_size = ev->data_len; payload = (char *)malloc(payload_size); snprintf(payload, payload_size+1, "%d", no_pings); nb_ba->publish_data(bin_prefix_id + bin_id, DOMAIN_LOCAL, NULL, 0, payload, payload_size); printf("Direct response for ping sequence %d has been successfuly published to %s\n", no_pings, string(prefix_id, PURSUIT_ID_LEN * 3, NODEID_LEN).c_str()); } else { /*rv_or_implicit = 1 -> pings published as: (SID/SID/SID/RID) - (AAAAAAAAAAAAAAAA/clientID/serverID/PingSequenceID)*/ prefix_id = string(published_scope_id, 0, PURSUIT_ID_LEN * 2) + string(published_scope_id, (PURSUIT_ID_LEN * 2) * 2, PURSUIT_ID_LEN * 2) + string(published_scope_id, PURSUIT_ID_LEN * 2, PURSUIT_ID_LEN * 2); bin_prefix_id = hex_to_chararray(prefix_id); /*ping sequence = information ID*/ id = string(c_id, (PURSUIT_ID_LEN * 2) * 3, PURSUIT_ID_LEN * 2); bin_id = hex_to_chararray(id); nb_ba->publish_info(bin_id, bin_prefix_id, DOMAIN_LOCAL, NULL, 0); } break; case START_PUBLISH: payload_size = sizeof(no_pings); payload = (char *)malloc(payload_size); gettimeofday(&live_tv, NULL); snprintf(payload, payload_size+1, "%d", no_pings); nb_ba->publish_data(bin_prefix_id + bin_id, DOMAIN_LOCAL, NULL, 0, payload, payload_size+1); printf("RV response for ping sequence %d has been successfuly published to %s\n", no_pings, string(prefix_id, PURSUIT_ID_LEN * 3, NODEID_LEN).c_str()); break; case RE_PUBLISH: cout << "Ping: republish ping " << endl; prefix_id = string(ev->id, 0, ev->id.length() - PURSUIT_ID_LEN); id = string(ev->id, ev->id.length() - PURSUIT_ID_LEN, PURSUIT_ID_LEN); nb_ba->publish_info(id, prefix_id, DOMAIN_LOCAL, NULL, 0); break; default: break; } delete ev; }