Пример #1
0
/*
 * Public Functions!
 */
static struct peersampler_context* cyclon_init(struct nodeID *myID, const void *metadata, int metadata_size, const char *config)
{
  struct tag *cfg_tags;
  struct peersampler_context *con;
  int res;

  con = cyclon_context_init();
  if (!con) return NULL;

  cfg_tags = config_parse(config);
  res = config_value_int(cfg_tags, "cache_size", &(con->cache_size));
  if (!res) {
    con->cache_size = DEFAULT_CACHE_SIZE;
  }
  res = config_value_int(cfg_tags, "sent_entries", &(con->sent_entries));
  if (!res) {
    con->sent_entries = con->cache_size / 2;
  }
  free(cfg_tags);

  con->local_cache = cache_init(con->cache_size, metadata_size, 0);
  if (con->local_cache == NULL) {
    free(con);
    return NULL;
  }

  con->pc = cyclon_proto_init(myID, metadata, metadata_size);
  if (!con->pc){
    free(con->local_cache);
    free(con);
    return NULL;
  }

  return con;
}
Пример #2
0
int main( int argc, char *argv[] )
{
    int		i;

    for (i=1; i<argc; i++)
	{
	    if (read_config(argv[i]) == -1)
		{
		    printf("Error opening \"%s\".\n", argv[i]);
		    return -1;
		}
	}

    printf("%10s == '%s'\n", "sju", config_value("sju") );
    printf("%10s == %i\n", "sju", config_value_int("sju") );
}
Пример #3
0
struct chunk_buffer *cb_init(const char *config)
{
  struct tag *cfg_tags;
  struct chunk_buffer *cb;
  int res, i;

  cb = malloc(sizeof(struct chunk_buffer));
  if (cb == NULL) {
    return cb;
  }
  memset(cb, 0, sizeof(struct chunk_buffer));

  cfg_tags = config_parse(config);
  if (!cfg_tags) {
    free(cb);
    return NULL;
  }
  res = config_value_int(cfg_tags, "size", &cb->size);
  if (!res) {
    free(cb);
    free(cfg_tags);

    return NULL;
  }
  free(cfg_tags);

  cb->buffer = malloc(sizeof(struct chunk) * cb->size);
  if (cb->buffer == NULL) {
    free(cb);
    return NULL;
  }
  memset(cb->buffer, 0, cb->size);
  for (i = 0; i < cb->size; i++) {
    cb->buffer[i].id = -1;
  }

  return cb;
}
Пример #4
0
static const int *ports_parse(const char *config)
{
  static int res[UDP_PORTS_NUM_MAX + 1];
  int i = 0;
  struct tag *cfg_tags;

  cfg_tags = config_parse(config);
  if (cfg_tags) {
    int j;

    for (j = 0; j < UDP_PORTS_NUM_MAX; j++) {
      char tag[8];

      sprintf(tag, "port%d", j);
      if (config_value_int(cfg_tags, tag, &res[i])) {
        i++;
      }
    }
  }
  free(cfg_tags);
  res[i] = -1;

  return res;
}
Пример #5
0
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;
}