/** If there's already an endpoint with the same public key, merge the new one with the old one. */ static void moveEndpointIfNeeded(struct IFCPeer* ep, struct Context* ic) { Log_debug(ic->logger, "Checking for old sessions to merge with."); uint8_t* key = CryptoAuth_getHerPublicKey(ep->cryptoAuthIf); for (uint32_t i = 0; i < ic->peerMap.count; i++) { struct IFCPeer* thisEp = ic->peerMap.values[i]; uint8_t* thisKey = CryptoAuth_getHerPublicKey(thisEp->cryptoAuthIf); if (thisEp != ep && !Bits_memcmp(thisKey, key, 32)) { Log_info(ic->logger, "Moving endpoint to merge new session with old."); ep->switchLabel = thisEp->switchLabel; SwitchCore_swapInterfaces(&thisEp->switchIf, &ep->switchIf); Allocator_free(thisEp->external->allocator); return; } } }
/** If there's already an endpoint with the same public key, merge the new one with the old one. */ static void moveEndpointIfNeeded(struct Peer* ep) { struct InterfaceController_Iface_pvt* ici = ep->ici; Log_debug(ici->ic->logger, "Checking for old sessions to merge with."); for (uint32_t i = 0; i < ici->peerMap.count; i++) { struct Peer* thisEp = ici->peerMap.values[i]; if (thisEp != ep && !Bits_memcmp(thisEp->addr.key, ep->addr.key, 32)) { Log_info(ici->ic->logger, "Moving endpoint to merge new session with old."); ep->addr.path = thisEp->addr.path; SwitchCore_swapInterfaces(&thisEp->switchIf, &ep->switchIf); Assert_true(ep->switchIf.connectedIf->send); Assert_true(thisEp->switchIf.connectedIf->send); Allocator_free(thisEp->alloc); Assert_true(!thisEp->switchIf.connectedIf->send); Assert_true(ep->switchIf.connectedIf->send); return; } } }