addPeerAddress method
void
addPeerAddress({
- required PeerId peerId,
- required FullAddress address,
- required AddressProperties properties,
- bool? canForward,
inherited
Adds an address for a peer to the routing table.
This method adds an address for a peer to the routing table. If the peer already exists in the routing table, the new address is added to the list of addresses for the peer. Otherwise, a new route is created for the peer with the new address.
The peerId parameter specifies the ID of the peer.
The address parameter specifies the address to add.
The properties parameter specifies the properties of the address.
The canForward parameter specifies whether the peer can forward
messages.
Implementation
void addPeerAddress({
required PeerId peerId,
required FullAddress address,
required AddressProperties properties,
bool? canForward,
}) {
// Ignore self.
if (peerId == selfId) {
return;
}
// If peer already exists in routing table.
if (routes.containsKey(peerId)) {
// Add the new address to the existing route.
routes[peerId]!.addAddress(
address: address,
properties: properties,
canForward: canForward,
);
} else {
// Create a new route for the peer.
routes[peerId] = Route(
peerId: peerId,
canForward: canForward ?? false,
address: (ip: address, properties: properties),
);
}
}