struct output_stream *out_stream_init(const char *fname, const char *config) { struct tag *cfg_tags; struct output_stream *res; res = malloc(sizeof(struct output_stream)); if (res == NULL) { return NULL; } #ifdef AVF res->out = &out_avf; #else res->out = &out_raw; #endif cfg_tags = config_parse(config); if (cfg_tags) { const char *type; type = config_value_str(cfg_tags, "dechunkiser"); if (type && !strcmp(type, "raw")) { res->out = &out_raw; } else if (type && !strcmp(type, "udp")) { res->out = &out_udp; } else if (type && !strcmp(type, "dummy")) { res->out = &out_dummy; } else if (type && !strcmp(type, "avf")) { #ifdef AVF res->out = &out_avf; #else free(res); free(cfg_tags); return NULL; #endif } else if (type && !strcmp(type, "play")) { #ifdef GTK res->out = &out_play; #else free(res); free(cfg_tags); return NULL; #endif } } free(cfg_tags); res->c = res->out->open(fname, config); if (res->c == NULL) { free(res); return NULL; } return res; }
struct nodeID *net_helper_init(const char *IPaddr, int port, const char *config) { struct timeval tout = NH_ML_INIT_TIMEOUT; int s, i; struct tag *cfg_tags; const char *res; const char *stun_server = "stun.ekiga.net"; int stun_port = 3478; const char *repo_address = NULL; int publish_interval = 60; int verbosity = DCLOG_ERROR; int bucketsize = 80000; /* this allows a burst of 80000 Bytes [Bytes] */ int rate = 10000000; /* 10Mbit/s [bits/s]*/ int queuesize = 1000000; /* up to 1MB of data will be stored in the shaper transmission queue [Bytes]*/ int RTXqueuesize = 1000000; /* up to 1 MB of data will be stored in the shaper retransmission queue [Bytes] */ double RTXholtdingtime = 1.0; /* [seconds] */ #ifndef _WIN32 signal(SIGPIPE, SIG_IGN); // workaround for a known issue in libevent2 with SIGPIPE on TPC connections #endif base = event_base_new(); lookup_array = calloc(lookup_max,sizeof(struct nodeID *)); cfg_tags = config_parse(config); if (!cfg_tags) { return NULL; } res = config_value_str(cfg_tags, "stun_server"); if (res) { stun_server = res; } config_value_int(cfg_tags, "stun_port", &stun_port); res = config_value_str(cfg_tags, "repo_address"); if (res) { repo_address = res; } config_value_int(cfg_tags, "publish_interval", &publish_interval); config_value_int(cfg_tags, "verbosity", &verbosity); config_value_int(cfg_tags, "bucketsize", &bucketsize); config_value_int(cfg_tags, "rate", &rate); config_value_int(cfg_tags, "queuesize", &queuesize); config_value_int(cfg_tags, "RTXqueuesize", &RTXqueuesize); config_value_double(cfg_tags, "RTXholtdingtime", &RTXholtdingtime); me = malloc(sizeof(nodeID)); if (me == NULL) { return NULL; } memset(me,0,sizeof(nodeID)); me->connID = -10; // dirty trick to spot later if the ml has called back ... me->refcnt = 1; for (i=0;i<NH_BUFFER_SIZE;i++) { sendingBuffer[i] = NULL; receivedBuffer[i].data = NULL; } mlRegisterErrorConnectionCb(&connError_cb); mlRegisterRecvConnectionCb(&receive_conn_cb); s = mlInit(1, tout, port, IPaddr, stun_port, stun_server, &init_myNodeID_cb, base); if (s < 0) { fprintf(stderr, "Net-helper : error initializing ML!\n"); free(me); return NULL; } mlSetVerbosity(verbosity); mlSetRateLimiterParams(bucketsize, rate, queuesize, RTXqueuesize, RTXholtdingtime); #ifdef MONL { void *repoclient; eventbase = base; // Initialize logging napaInitLog(verbosity, NULL, NULL); repInit(""); repoclient = repOpen(repo_address, publish_interval); //repository.napa-wine.eu // NULL is inow valid for disabled repo // if (repoclient == NULL) fatal("Unable to initialize repoclient"); monInit(base, repoclient); } #endif free(cfg_tags); while (me->connID<-1) { // event_base_once(base,-1, EV_TIMEOUT, &t_out_cb, NULL, &tout); event_base_loop(base,EVLOOP_ONCE); } timeoutFired = 0; // fprintf(stderr,"Net-helper init : back from init!\n"); return me; }