}
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);
void *id;
if ((net->stun.port_ext && host == net->net_config.local_host) ||
- peer->state.connected || peer->endpoint)
+ peer->state.connected || peer->endpoint || host->gateway)
continue;
id = pex_msg_append(PEX_ID_LEN);
D_PEER(net, peer, "send query for %d hosts", hosts);
pex_msg_send(net, peer);
+ peer->state.last_query_sent = now;
return;
}
}
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);
+ struct network_host *host;
+
+ cur = pex_msg_peer(net, data, false);
if (!cur || !cur->state.connected)
continue;
+ host = container_of(peer, struct network_host, peer);
+ if (host->gateway)
+ continue;
+
if (!pex_msg_add_peer_endpoint(net, cur, peer))
resp++;
}
struct sockaddr_in6 *addr)
{
struct pex_update_request *req = (struct pex_update_request *)data;
+ struct pex_endpoint_port_notify *port_data;
struct pex_msg_update_send_ctx ctx = {};
uint64_t req_version = be64_to_cpu(req->cur_version);
int *query_count;
return;
if (req_version >= net->net_data_version)
- return;
+ goto out;
pex_msg_update_response_init(&ctx, net->config.pubkey, net->config.auth_key,
peer->key, !!addr, (void *)data,
pex_msg_send_ext(net, peer, addr);
done = !pex_msg_update_response_continue(&ctx);
}
+
+out:
+ if (peer->state.connected || !net->net_config.local_host)
+ return;
+
+ pex_msg_init_ext(net, PEX_MSG_ENDPOINT_PORT_NOTIFY, !!addr);
+
+ port_data = pex_msg_append(sizeof(*port_data));
+ if (net->stun.port_ext)
+ port_data->port = htons(net->stun.port_ext);
+ else
+ port_data->port = htons(net->net_config.local_host->peer.port);
+
+ pex_msg_send_ext(net, peer, addr);
}
static void
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;