Beispiel #1
0
link_t mesh_add(mesh_t mesh, lob_t json, pipe_t pipe)
{
  link_t link;
  lob_t keys, paths;
  uint8_t csid;

  if(!mesh || !json) return LOG("bad args");
  LOG("mesh add %s",lob_json(json));
  link = link_get(mesh, hashname_vchar(lob_get(json,"hashname")));
  keys = lob_get_json(json,"keys");
  paths = lob_get_array(json,"paths");
  if(!link) link = link_keys(mesh, keys);
  if(!link) LOG("no hashname");
  
  LOG("loading keys/paths");
  if(keys && (csid = hashname_id(mesh->keys,keys))) link_load(link, csid, keys);

  // handle any pipe/paths
  if(pipe) link_pipe(link, pipe);
  lob_t path;
  for(path=paths;path;path = lob_next(path)) link_path(link,path);
  
  lob_free(keys);
  lob_freeall(paths);

  return link;
}
Beispiel #2
0
int main(int argc, char **argv)
{
  mesh_t meshA = mesh_new();
  fail_unless(meshA);
  lob_t secretsA = mesh_generate(meshA);
  fail_unless(secretsA);

  mesh_t meshB = mesh_new();
  fail_unless(meshB);
  lob_t secretsB = mesh_generate(meshB);
  fail_unless(secretsB);
  
  net_tcp4_t netA = net_tcp4_new(meshA, NULL);
  fail_unless(netA);
  fail_unless(netA->port > 0);
  fail_unless(netA->path);
  LOG("netA %.*s",netA->path->head_len,netA->path->head);

  net_tcp4_t netB = net_tcp4_new(meshB, NULL);
  fail_unless(netB);
  fail_unless(netB->port > 0);
  LOG("netB %.*s",netB->path->head_len,netB->path->head);
  
  link_t linkAB = link_keys(meshA, meshB->keys);
  link_t linkBA = link_keys(meshB, meshA->keys);
  fail_unless(linkAB);
  fail_unless(linkBA);
  
  fail_unless(link_path(linkAB,netB->path));
  fail_unless(link_path(linkBA,netA->path));
  
  link_sync(linkAB);
  // let tcp go back and forth enough, need a better way to do this
  int loop;
  for(loop = 10; loop; loop--)
  {
    net_tcp4_loop(netB);
    net_tcp4_loop(netA);
  }
  fail_unless(e3x_exchange_out(linkBA->x,0) >= e3x_exchange_out(linkAB->x,0));
  fail_unless(e3x_exchange_out(linkBA->x,0) == e3x_exchange_out(linkAB->x,0));

  return 0;
}
Beispiel #3
0
int main(int argc, char **argv)
{
  mesh_t meshA = mesh_new(3);
  fail_unless(meshA);
  lob_t secretsA = mesh_generate(meshA);
  fail_unless(secretsA);

  mesh_t meshB = mesh_new(3);
  fail_unless(meshB);
  lob_t secretsB = mesh_generate(meshB);
  fail_unless(secretsB);
  
  net_serial_t netA = net_serial_new(meshA, NULL);
  fail_unless(netA);
  pipe_t pAB = net_serial_add(netA, "sAB", readerA, writerA, 64);
  fail_unless(pAB);

  net_serial_t netB = net_serial_new(meshB, NULL);
  fail_unless(netB);
  pipe_t pBA = net_serial_add(netB, "sBA", readerB, writerB, 64);
  fail_unless(pBA);

  link_t linkAB = link_pipe(link_keys(meshA, meshB->keys), pAB);
  link_t linkBA = link_pipe(link_keys(meshB, meshA->keys), pBA);
  fail_unless(linkAB);
  fail_unless(linkBA);

  link_sync(linkAB);
  // let serial go go go
  int loop;
  for(loop = 2000; loop; loop--)
  {
    net_serial_loop(netB);
    net_serial_loop(netA);
  }

  LOG("BA %d AB %d",e3x_exchange_out(linkBA->x,0),e3x_exchange_out(linkAB->x,0));
  fail_unless(e3x_exchange_out(linkBA->x,0) >= e3x_exchange_out(linkAB->x,0));
  fail_unless(e3x_exchange_out(linkBA->x,0) == e3x_exchange_out(linkAB->x,0));


  return 0;
}
Beispiel #4
0
int main(int argc, char **argv)
{
    mesh_t meshA = mesh_new(3);
    fail_unless(meshA);
    lob_t secretsA = mesh_generate(meshA);
    fail_unless(secretsA);

    mesh_t meshB = mesh_new(3);
    fail_unless(meshB);
    lob_t secretsB = mesh_generate(meshB);
    fail_unless(secretsB);

    net_udp4_t netA = net_udp4_new(meshA, NULL);
    fail_unless(netA);
    fail_unless(netA->port > 0);
    fail_unless(netA->path);
    fail_unless(lob_match(meshA->paths,"type","udp4"));
    LOG("netA %.*s",netA->path->head_len,netA->path->head);

    net_udp4_t netB = net_udp4_new(meshB, NULL);
    fail_unless(netB);
    fail_unless(netB->port > 0);
    LOG("netB %.*s",netB->path->head_len,netB->path->head);

    link_t linkAB = link_keys(meshA, meshB->keys);
    link_t linkBA = link_keys(meshB, meshA->keys);
    fail_unless(linkAB);
    fail_unless(linkBA);

    fail_unless(link_path(linkAB,netB->path));
    fail_unless(link_path(linkBA,netA->path));

    link_sync(linkAB);
    net_udp4_receive(netB);
    fail_unless(e3x_exchange_out(linkBA->x,0) >= e3x_exchange_out(linkAB->x,0));
    net_udp4_receive(netA);
    fail_unless(e3x_exchange_out(linkBA->x,0) == e3x_exchange_out(linkAB->x,0));

    return 0;
}
Beispiel #5
0
net_loopback_t net_loopback_new(mesh_t a, mesh_t b)
{
  net_loopback_t pair;

  if(!(pair = malloc(sizeof (struct net_loopback_struct)))) return LOG("OOM");
  memset(pair,0,sizeof (struct net_loopback_struct));
  if(!(pair->pipe = pipe_new("pair")))
  {
    free(pair);
    return LOG("OOM");
  }
  pair->a = a;
  pair->b = b;
  pair->pipe->id = strdup("loopback");
  pair->pipe->arg = pair;
  pair->pipe->send = pair_send;

  // ensure they're linked and piped together
  link_pipe(link_keys(a,b->keys),pair->pipe);
  link_pipe(link_keys(b,a->keys),pair->pipe);

  return pair;
}