mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-07-28 11:02:07 +00:00
Catch relay node dial errors
This commit is contained in:
parent
84539dffce
commit
042b588a48
@ -188,13 +188,18 @@ export class Peer {
|
|||||||
|
|
||||||
async _connectPeer (peer: PeerInfo): Promise<void> {
|
async _connectPeer (peer: PeerInfo): Promise<void> {
|
||||||
assert(this._node);
|
assert(this._node);
|
||||||
console.log(`Dialling peer ${peer.id.toString()}`);
|
|
||||||
|
|
||||||
// Check if discovered the relay node
|
// Check if discovered the relay node
|
||||||
if (this._relayNodeMultiaddr) {
|
if (this._relayNodeMultiaddr) {
|
||||||
const relayNodePeerId = this._relayNodeMultiaddr.getPeerId();
|
const relayMultiaddr = this._relayNodeMultiaddr;
|
||||||
|
const relayNodePeerId = relayMultiaddr.getPeerId();
|
||||||
|
|
||||||
if (relayNodePeerId && relayNodePeerId === peer.id.toString()) {
|
if (relayNodePeerId && relayNodePeerId === peer.id.toString()) {
|
||||||
await this._node.dial(this._relayNodeMultiaddr);
|
console.log(`Dialling relay peer ${peer.id.toString()} using multiaddr ${relayMultiaddr.toString()}`);
|
||||||
|
await this._node.dial(relayMultiaddr).catch(err => {
|
||||||
|
console.log(`Could not dial relay ${relayMultiaddr.toString()}`, err);
|
||||||
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -202,6 +207,7 @@ export class Peer {
|
|||||||
// Dial them when we discover them
|
// Dial them when we discover them
|
||||||
// Attempt to dial all the multiaddrs of the discovered peer (to connect through relay)
|
// Attempt to dial all the multiaddrs of the discovered peer (to connect through relay)
|
||||||
for (const peerMultiaddr of peer.multiaddrs) {
|
for (const peerMultiaddr of peer.multiaddrs) {
|
||||||
|
console.log(`Dialling peer ${peer.id.toString()} using multiaddr ${peerMultiaddr.toString()}`);
|
||||||
const stream = await this._node.dialProtocol(peerMultiaddr, PROTOCOL).catch(err => {
|
const stream = await this._node.dialProtocol(peerMultiaddr, PROTOCOL).catch(err => {
|
||||||
console.log(`Could not dial ${peerMultiaddr.toString()}`, err);
|
console.log(`Could not dial ${peerMultiaddr.toString()}`, err);
|
||||||
});
|
});
|
||||||
@ -214,7 +220,7 @@ export class Peer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_handleStream (peerId: PeerId, stream: P2PStream): void {
|
_handleStream (peerId: PeerId, stream: P2PStream): void {
|
||||||
console.log('Stream after connection', stream);
|
// console.log('Stream after connection', stream);
|
||||||
const messageStream = pushable<string>({ objectMode: true });
|
const messageStream = pushable<string>({ objectMode: true });
|
||||||
|
|
||||||
// Send message to pipe from stdin
|
// Send message to pipe from stdin
|
||||||
|
Loading…
Reference in New Issue
Block a user