// 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) { link->csid = link->x->csid; // repair in case mesh_unlink was called, any better place? return link; } LOG("adding %x key to link %s",csid,hashname_short(link->id)); // key must be bin if(key->body_len) { copy = lob_new(); lob_body(copy,key->body,key->body_len); }else{ util_hex(&csid,1,hex); copy = lob_get_base32(key,hex); } link->x = e3x_exchange_new(link->mesh->self, csid, copy); if(!link->x) { LOG("invalid %x key %s %s",csid,util_hex(copy->body,copy->body_len,NULL),lob_json(key)); lob_free(copy); return NULL; } link->csid = csid; link->key = copy; e3x_exchange_out(link->x, util_sys_seconds()); LOG("new exchange session to %s",hashname_short(link->id)); return link; }
// 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 = e3x_exchange_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(e3x_exchange_token(link->x),16,link->token); xht_set(link->mesh->index,link->token,link); e3x_exchange_out(link->x, util_sys_seconds()); LOG("new session token %s to %s",link->token,link->id->hashname); return link; }