return;
}
+ if ((h_new ? h_new : h_old)->indirect)
+ return;
+
if (h_new)
ret = wg_peer_update(net, h_new, h_old ? WG_PEER_UPDATE : WG_PEER_CREATE);
else
avl_for_each_element(&net->hosts, host, node) {
if (host == local)
continue;
+ host->peer.indirect = false;
if (host->gateway && strcmp(host->gateway, local_name) != 0)
- continue;
+ host->peer.indirect = true;
if (local->gateway && strcmp(local->gateway, network_host_name(host)) != 0)
- continue;
+ host->peer.indirect = true;
vlist_add(&net->peers, &host->peer.node, host->peer.key);
}
wg_peer_refresh(net);
vlist_for_each_element(&net->peers, peer, node) {
- if (peer->state.connected)
+ if (peer->state.connected || peer->indirect)
continue;
ep = network_peer_next_endpoint(peer);
}
static struct network_peer *
-pex_msg_peer(struct network *net, const uint8_t *id)
+pex_msg_peer(struct network *net, const uint8_t *id, bool allow_indirect)
{
struct network_peer *peer;
uint8_t key[WG_KEY_LEN] = {};
D_NET(net, "can't find peer %s", pex_peer_id_str(id));
return NULL;
}
+ if (peer->indirect && !allow_indirect)
+ return NULL;
return peer;
}
struct network_peer *cur;
vlist_for_each_element(&net->peers, cur, node) {
- if (cur == peer || !cur->state.connected)
+ if (cur == peer || !cur->state.connected || cur->indirect)
continue;
pex_msg_init(net, PEX_MSG_NOTIFY_PEERS);
continue;
}
- cur = pex_msg_peer(net, data->peer_id);
+ cur = pex_msg_peer(net, data->peer_id, false);
if (!cur || cur == peer)
continue;
pex_msg_init(net, PEX_MSG_NOTIFY_PEERS);
for (; len >= 8; data += 8, len -= 8) {
- cur = pex_msg_peer(net, data);
+ cur = pex_msg_peer(net, data, false);
if (!cur || !cur->state.connected)
continue;
if (!hdr)
continue;
- peer = pex_msg_peer(net, hdr->id);
+ peer = pex_msg_peer(net, hdr->id, false);
if (!peer)
continue;
case PEX_MSG_PONG:
break;
case PEX_MSG_UPDATE_REQUEST:
- peer = pex_msg_peer(net, hdr->id);
+ peer = pex_msg_peer(net, hdr->id, true);
network_pex_recv_update_request(net, peer, data, hdr->len,
addr);
break;
ep_idx = ENDPOINT_TYPE_ENDPOINT_PORT_NOTIFY;
fallthrough;
case PEX_MSG_ENDPOINT_NOTIFY:
- peer = pex_msg_peer(net, hdr->id);
+ peer = pex_msg_peer(net, hdr->id, true);
if (!peer)
break;