Closed KrishnaPG closed 4 years ago
You have to error handle the socket by attaching an onerror handler to the stream
Thank you. Calling socket.end()
causes the connection to reconnect indefinitely. How to control this behavior? For example,
swarm.on('connection', (socket, details) => {
if(some condition met)
socket.end(); // close the connection
})
But this keeps reconnecting. How to avoid it, and just close (and stay closed) ?
a guess, @KrishnaPG tell if it works
swarm.on('connection', (socket, details) => {
if(some condition met) {
details.ban() // stop reconnecting to peer
socket.end(); // close the connection
}
})
Thank you @freddi301 Wouldn't ban()
prohobit the reconnection to that peer forever (as in next time if we need to search, say, when the current active connection goes away and need to find alternatives)?
According to docs peers gets banned for queue.banned
Option 1: info.ban()
+ hyperswarm({queue: {banned: 4000}})
Option 2: info.ban()
+ info.backoff()
(found here https://github.com/hyperswarm/hyperswarm#infobackoff)
Option 3: info.ban(true)
(found here https://github.com/hyperswarm/hyperswarm/blob/master/lib/peer-info.js#L113)
Option 4: use underlying modules to implement your own swarm (https://github.com/hyperswarm)
what is your goal?
Running the below code in two different terminals, if one instance is stopped (ctrl + c), the other instance just crashes !!
The crash happens with below error:
It is not clear why the app would crash if its peer exits. How to handle this gracefully?
Tried doing
socket.end
on the other app. But that would keep reconnecting.