// This is the first function that incoming Hello data will // see. This checks if the data appears to be signed, and passes it // on to validate the content of the data. void HelloProtocol::onContent(const ndn::Interest& interest, const ndn::Data& data) { _LOG_DEBUG("Received data for INFO(name): " << data.getName()); if (data.getSignature().hasKeyLocator()) { if (data.getSignature().getKeyLocator().getType() == ndn::KeyLocator::KeyLocator_Name) { _LOG_DEBUG("Data signed with: " << data.getSignature().getKeyLocator().getName()); } } m_nlsr.getValidator().validate(data, ndn::bind(&HelloProtocol::onContentValidated, this, _1), ndn::bind(&HelloProtocol::onContentValidationFailed, this, _1, _2)); }
void validate(const ndn::Data& data) { BOOST_CHECK_EQUAL(data.getFreshnessPeriod(), m_expectedFreshnessPeriod); ndn::Block payload = data.getContent(); m_buffer.appendByteArray(payload.value(), payload.value_size()); // uint64_t segmentNo = data.getName()[-1].toSegment(); if (data.getFinalBlockId() != data.getName()[-1]) { return; } // wrap data in a single Content TLV for easy parsing m_buffer.prependVarNumber(m_buffer.size()); m_buffer.prependVarNumber(ndn::tlv::Content); BOOST_TEST_CHECKPOINT("creating parser"); ndn::Block parser(m_buffer.buf(), m_buffer.size()); BOOST_TEST_CHECKPOINT("parsing aggregated response"); parser.parse(); BOOST_REQUIRE_EQUAL(parser.elements_size(), m_publisher.getLimit()); uint64_t expectedNo = m_publisher.getLimit() - 1; for (ndn::Block::element_const_iterator i = parser.elements_begin(); i != parser.elements_end(); ++i) { uint64_t number = readNonNegativeInteger(*i); BOOST_REQUIRE_EQUAL(number, expectedNo); --expectedNo; } }
virtual void onData(const ndn::Interest& interest, const ndn::Data& data) { int dollarfound=0; int hashfound=0; int i=0; cout << data.getName().size() << endl; int comp_size=data.getName().size(); string last_comp=data.getName().get(comp_size-1).toUri(); string check=UriDecode(last_comp); cout<<check<<endl; cout<<"Last component is "<<last_comp<<endl; std::size_t found = check.find("#"); if (found!=std::string::npos) { hashfound=1; } found = check.find("$"); if (found!=std::string::npos) { dollarfound=1; } printf("DollarFound:%d and HashFound:%d\n",dollarfound,hashfound); std::cout << "Received Data " << data << std::endl; const ndn::Block& payload = data.getContent(); std:: cout << "payload: "; std::cout.write(reinterpret_cast<const char*>(payload.value()), payload.value_size()); std:: cout << std::endl; if(dollarfound==1) { printf("Inside Dollar Found\n"); const char *sending=reinterpret_cast<const char*>(payload.value()); string received=string(sending); int max_seg_consumer=stoi(received); printf("Maximum Number of Segments is =%d\n",max_seg_consumer); //Write code to express interest for the 0th segment string seg_req_0=UriDecode(data.getName().toUri()); seg_req_0.pop_back(); seg_req_0.append(to_string(max_seg_consumer)); seg_req_0.append("/#0"); printf("String for 0th segment is :"); cout<<seg_req_0<<endl; char str_send[2][1000]; memset(&str_send,0,sizeof(str_send)); strcpy(str_send[0], seg_req_0.c_str()); cout<<"String being sent in $ is:"<<str_send[0]<<endl; const ndn::Name name1(str_send[0]); ndn::Interest request(name1); m_face.expressInterest(request, bind(&Consumer::onData, this, _1, _2), bind(&Consumer::onTimeout, this, _1)); // m_face.processEvents(); } if(hashfound==1){ printf("Inside Hash Fund\n"); //Write code to print to the file and ask the next segment string filename; for(i=0;i<comp_size-2;i++) { string mid=data.getName().get(i).toUri(); string checking=UriDecode(mid); filename = filename + '_' +mid; } char node_name[node_size]; gethostname(node_name,node_size); string node_n=string(node_name); node_n.append("-"); node_n=node_n + filename; cout<<node_n<<endl; FILE *fp1=fopen(node_n.c_str(),"a"); fseek(fp1, 0L, SEEK_END); int start_ind=0; start_ind=stoi(check.substr(1)); const char *sending=reinterpret_cast<const char*>(payload.value()); int start1=start_ind*MAX_SEG; fseek(fp1,start1,SEEK_SET); int just_checking=0; if (!(just_checking=fwrite(sending,1,(int)payload.value_size(),fp1))) { fprintf(stderr, "Failure"); //perror(???) I sometimes see code that says perror here and I don't know //exactly what this does. } printf("Just checking.......%d\n",just_checking); //fwrite(sending,1,(int)payload.value_size(),fp1); // fwrite(sending,1,payload.value_size(),fp1); fclose(fp1); /* int start_ind=stoi(check.substr(1)); std::ofstream ofs; ofs.open (node_n, std::ofstream::out | std::ofstream::app); ofs.write(reinterpret_cast<const char*>(payload.value()), payload.value_size()); ofs.close();*/ start_ind++; // printf("Maximum segment count inside the hash function before the condition is:%d and value of start is: %d\n",max_seg_consumer,start_ind); int max_seg_consumer=stoi(UriDecode(data.getName().get(comp_size-2).toUri())); if(start_ind<max_seg_consumer) { printf("Inside the if consition for max segments\n"); string seg_req=UriDecode(data.getName().toUri()); size_t found = seg_req.find_last_of("#"); seg_req=seg_req.substr(0,found+1); seg_req.append(to_string(start_ind)); char str_send[5][1000]; memset(&str_send,0,sizeof(str_send)); strcpy(str_send[0], seg_req.c_str()); cout<<"String that is being sent in ####"<<str_send<<endl; const ndn::Name name1(str_send[0]); ndn::Interest request(name1); m_face.expressInterest(request, bind(&Consumer::onData, this, _1, _2), bind(&Consumer::onTimeout, this, _1)); } else { char buf[16]; snprintf(buf, 16, "%lu", time(NULL)); strcat(timer,"\n"); char tab2[100]; memset(&tab2,0,sizeof(tab2)); strcpy(tab2, node_n.c_str()); strcat(timer,tab2); strcat(timer," End: "); strcat(timer,buf); strcat(timer,"\n"); FILE *fp3; fp3=fopen("logs_shivani.txt","a"); fwrite(timer,1,sizeof(timer),fp3); fclose(fp3); memset(&timer,0,sizeof(timer)); } } }