Make send() retry with exponential backoff

pull/71/head
Eugene Kim 6 years ago
parent 8d277fb796
commit bdf7e37ddc
  1. 15
      p2p/peer.go

@ -129,12 +129,21 @@ func sendWithSocketClient(ip, port string, message []byte) (err error) {
}
// Send a message to another node with given port.
func send(ip, port string, message []byte) (returnMessage string) {
func send(ip, port string, message []byte) {
// Add attack code here.
attack.GetInstance().Run()
sendWithSocketClient(ip, port, message)
return
backoff := NewExpBackoff(250*time.Millisecond, 10*time.Second, 2)
for {
err := sendWithSocketClient(ip, port, message)
if err == nil {
break
}
log.Printf("sleeping %s before trying to send to %s again",
backoff.Cur, net.JoinHostPort(ip, port))
backoff.Sleep()
}
}
func DialWithSocketClient(ip, port string) (conn net.Conn, err error) {

Loading…
Cancel
Save