Exemplo n.º 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;
}
Exemplo n.º 2
0
void FlipPath::update(SDL_Event event){
    if (state == IDLE) {
        if (timer.is_timeup()) {
            state = ANIME;
            timer.reset();
        }
    }else{
        //Disconnect path if needed
        if (next) unlink_path(this, next);
        
        //Update index and rotation
        int next_index = cur_index + 1;
        if (next_index >= next_rotate.size()) next_index = 0;
        
        Vector rot = next_rotate[next_index];
        cur_rotate.x = adjust(cur_rotate.x, rot.x, 3);
        cur_rotate.y = adjust(cur_rotate.y, rot.y, 3);
        cur_rotate.z = adjust(cur_rotate.z, rot.z, 3);
        
        if (cur_rotate == rot) {
            cur_index  = next_index;
            link_path(this, next_path[cur_index]);
            
            state = IDLE;
            timer.start();
        }
    }
    
    //Update
    for (int i = 0; i < next_path.size();i++) {
        next_path[i]->update(event);
    }
}
Exemplo n.º 3
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;
}
Exemplo n.º 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;
}