void ccnl_relay_udp(struct ccnl_relay_s *relay, int port) { struct ccnl_if_s *i; if (port < 0) return; i = &relay->ifs[relay->ifcount]; i->sock = ccnl_open_udpdev(port, &i->addr.ip4); if (i->sock <= 0) { DEBUGMSG(WARNING, "sorry, could not open udp device (port %d)\n", port); return; } // i->frag = CCNL_DGRAM_FRAG_NONE; #ifdef USE_SUITE_CCNB if (suite == CCNL_SUITE_CCNB) i->mtu = CCN_DEFAULT_MTU; #endif #ifdef USE_SUITE_CCNTLV if (suite == CCNL_SUITE_CCNTLV) i->mtu = CCN_DEFAULT_MTU; #endif #ifdef USE_SUITE_NDNTLV if (suite == CCNL_SUITE_NDNTLV) i->mtu = NDN_DEFAULT_MTU; #endif i->fwdalli = 1; relay->ifcount++; DEBUGMSG(INFO, "UDP interface (%s) configured\n", ccnl_addr2ascii(&i->addr)); if (relay->defaultInterfaceScheduler) i->sched = relay->defaultInterfaceScheduler(relay, ccnl_interface_CTS); }
int main(int argc, char **argv) { int opt; int udpport = 0; char *prefix, *defaultgw; struct ccnl_if_s *i; struct ccnl_forward_s *fwd; sockunion sun; srandom(time(NULL)); int suite = CCNL_SUITE_NDNTLV; while ((opt = getopt(argc, argv, "hs:u:v:")) != -1) { switch (opt) { case 's': opt = ccnl_str2suite(optarg); if (opt >= 0 && opt < CCNL_SUITE_LAST) suite = opt; else fprintf(stderr, "Suite parameter <%s> ignored.\n", optarg); break; case 'u': udpport = atoi(optarg); break; case 'v': debug_level = atoi(optarg); break; case 'h': default: usage: fprintf(stderr, "usage: %s [options] PREFIX DGWIP/DGWUDPPORT\n" "options: [-h] [-s SUITE] [-u udpport] [-v debuglevel]\n" "example: %s /ndn 128.252.153.194/6363\n", argv[0], argv[0]); exit(EXIT_FAILURE); } } if ((optind+1) >= argc) goto usage; prefix = argv[optind]; defaultgw = argv[optind+1]; ccnl_core_init(); // if (theRelay.suite == CCNL_SUITE_NDNTLV && !udpport) udpport = NDN_UDP_PORT; i = &theRelay.ifs[0]; i->mtu = NDN_DEFAULT_MTU; i->fwdalli = 1; i->sock = ccnl_open_udpdev(udpport); if (i->sock < 0) exit(-1); theRelay.ifcount++; fprintf(stderr, "NDN minimalrelay started, listening on UDP port %d\n", udpport); inet_aton(strtok(defaultgw,"/"), &sun.ip4.sin_addr); sun.ip4.sin_port = atoi(strtok(NULL, "")); fwd = (struct ccnl_forward_s *) ccnl_calloc(1, sizeof(*fwd)); fwd->prefix = ccnl_URItoPrefix(prefix, suite, NULL, NULL); fwd->suite = suite; fwd->face = ccnl_get_face_or_create(&theRelay, 0, &sun.sa, sizeof(sun.ip4)); fwd->face->flags |= CCNL_FACE_FLAGS_STATIC; theRelay.fib = fwd; ccnl_set_timer(1000000, ccnl_minimalrelay_ageing, &theRelay, 0); ccnl_io_loop(&theRelay); return 0; }
void ccnl_relay_config(struct ccnl_relay_s *relay, char *ethdev, int udpport, int tcpport, char *uxpath, int max_cache_entries, char *crypto_face_path) { struct ccnl_if_s *i; char h[1024]; DEBUGMSG(99, "ccnl_relay_config\n"); relay->max_cache_entries = max_cache_entries; #ifdef USE_SCHEDULER relay->defaultFaceScheduler = ccnl_relay_defaultFaceScheduler; relay->defaultInterfaceScheduler = ccnl_relay_defaultInterfaceScheduler; #endif #ifdef USE_ETHERNET // add (real) eth0 interface with index 0: if (ethdev) { i = &relay->ifs[relay->ifcount]; i->sock = ccnl_open_ethdev(ethdev, &i->addr.eth, CCNL_ETH_TYPE); i->mtu = 1500; i->reflect = 1; i->fwdalli = 1; if (i->sock >= 0) { relay->ifcount++; DEBUGMSG(99, "new ETH interface (%s %s) configured\n", ethdev, ccnl_addr2ascii(&i->addr)); if (relay->defaultInterfaceScheduler) i->sched = relay->defaultInterfaceScheduler(relay, ccnl_interface_CTS); } else fprintf(stderr, "sorry, could not open eth device\n"); } #endif // USE_ETHERNET if (udpport > 0) { i = &relay->ifs[relay->ifcount]; i->sock = ccnl_open_udpdev(udpport, &i->addr.ip4); // i->frag = CCNL_DGRAM_FRAG_NONE; i->mtu = CCN_DEFAULT_MTU; i->fwdalli = 1; if (i->sock >= 0) { relay->ifcount++; DEBUGMSG(99, "new UDP interface (ip4 %s) configured\n", ccnl_addr2ascii(&i->addr)); if (relay->defaultInterfaceScheduler) i->sched = relay->defaultInterfaceScheduler(relay, ccnl_interface_CTS); } else fprintf(stderr, "sorry, could not open udp device\n"); } #ifdef USE_HTTP_STATUS if (tcpport) { relay->http = ccnl_http_new(relay, tcpport); } #endif // USE_HTTP_STATUS #ifdef USE_UNIXSOCKET if (uxpath) { i = &relay->ifs[relay->ifcount]; i->sock = ccnl_open_unixpath(uxpath, &i->addr.ux); i->mtu = 4096; if (i->sock >= 0) { relay->ifcount++; DEBUGMSG(99, "new UNIX interface (%s) configured\n", ccnl_addr2ascii(&i->addr)); if (relay->defaultInterfaceScheduler) i->sched = relay->defaultInterfaceScheduler(relay, ccnl_interface_CTS); } else fprintf(stderr, "sorry, could not open unix datagram device\n"); } #ifdef USE_SIGNATURES if(crypto_face_path) { //sending interface + face i = &relay->ifs[relay->ifcount]; i->sock = ccnl_open_unixpath(crypto_face_path, &i->addr.ux); i->mtu = 4096; if (i->sock >= 0) { relay->ifcount++; DEBUGMSG(99, "new UNIX interface (%s) configured\n", ccnl_addr2ascii(&i->addr)); if (relay->defaultInterfaceScheduler) i->sched = relay->defaultInterfaceScheduler(relay, ccnl_interface_CTS); ccnl_crypto_create_ccnl_crypto_face(relay, crypto_face_path); relay->crypto_path = crypto_face_path; } else fprintf(stderr, "sorry, could not open unix datagram device\n"); //receiving interface memset(h,0,sizeof(h)); sprintf(h,"%s-2",crypto_face_path); i = &relay->ifs[relay->ifcount]; i->sock = ccnl_open_unixpath(h, &i->addr.ux); i->mtu = 4096; if (i->sock >= 0) { relay->ifcount++; DEBUGMSG(99, "new UNIX interface (%s) configured\n", ccnl_addr2ascii(&i->addr)); if (relay->defaultInterfaceScheduler) i->sched = relay->defaultInterfaceScheduler(relay, ccnl_interface_CTS); //create_ccnl_crypto_face(relay, crypto_face_path); } else fprintf(stderr, "sorry, could not open unix datagram device\n"); } #endif //USE_SIGNATURES #endif // USE_UNIXSOCKET ccnl_set_timer(1000000, ccnl_ageing, relay, 0); }