// load in the key to existing link link_t link_load(link_t link, uint8_t csid, lob_t key) { char hex[3]; lob_t copy; if(!link || !csid || !key) return LOG("bad args"); if(link->x) return link; LOG("adding %x key to link %s",csid,link->id->hashname); // key must be bin if(key->body_len) { copy = lob_copy(key); }else{ util_hex(&csid,1,hex); copy = lob_get_base32(key,hex); } link->x = exchange3_new(link->mesh->self, csid, copy); if(!link->x) { lob_free(copy); return LOG("invalid %x key %d %s",csid,key->body_len,lob_json(key)); } link->csid = csid; link->key = copy; // route packets to this token util_hex(exchange3_token(link->x),16,link->token); xht_set(link->mesh->index,link->token,link); exchange3_out(link->x, platform_seconds()); LOG("delivering session token %s to %s",link->token,link->id->hashname); return link; }
int path_alive(path_t p) { unsigned long now; if(!p) return 0; now = platform_seconds(); if((now - p->tin) < 30) return 1; return 0; }