add a fallback reconnection if no keepalives are recieved within ~24 hours
This commit is contained in:
parent
2cbc8f8496
commit
f5fbce3ee6
@ -2,6 +2,7 @@ package libnmdc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -24,10 +25,11 @@ type HubConnection struct {
|
|||||||
OnEvent chan HubEvent
|
OnEvent chan HubEvent
|
||||||
|
|
||||||
// Private state
|
// Private state
|
||||||
conn net.Conn // this is an interface
|
conn net.Conn // this is an interface
|
||||||
connValid bool
|
connValid bool
|
||||||
sentOurHello bool
|
sentOurHello bool
|
||||||
autoReconnect bool
|
autoReconnect bool
|
||||||
|
lastDataRecieved time.Time
|
||||||
|
|
||||||
supports map[string]struct{}
|
supports map[string]struct{}
|
||||||
}
|
}
|
||||||
@ -398,6 +400,7 @@ func (this *HubConnection) worker() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if nbytes > 0 {
|
if nbytes > 0 {
|
||||||
|
this.lastDataRecieved = time.Now()
|
||||||
fullBuffer += string(readBuff[0:nbytes])
|
fullBuffer += string(readBuff[0:nbytes])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -416,6 +419,10 @@ func (this *HubConnection) worker() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err == nil && time.Now().Sub(this.lastDataRecieved) > RECONNECT_IF_NO_DATA_RECIEVED_IN {
|
||||||
|
err = fmt.Errorf("No packets recieved since %s, connection presumed lost", this.lastDataRecieved.Format(time.RFC3339))
|
||||||
|
}
|
||||||
|
|
||||||
// Maybe we disconnected
|
// Maybe we disconnected
|
||||||
// Perform this check *last*, to ensure we've had a final shot at
|
// Perform this check *last*, to ensure we've had a final shot at
|
||||||
// clearing out any queued messages
|
// clearing out any queued messages
|
||||||
|
11
libnmdc.go
11
libnmdc.go
@ -9,11 +9,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
DEFAULT_CLIENT_TAG string = "libnmdc.go"
|
DEFAULT_CLIENT_TAG string = "libnmdc.go"
|
||||||
DEFAULT_CLIENT_VERSION string = "0.11"
|
DEFAULT_CLIENT_VERSION string = "0.11"
|
||||||
DEFAULT_HUB_NAME string = "(unknown)"
|
DEFAULT_HUB_NAME string = "(unknown)"
|
||||||
SEND_KEEPALIVE_EVERY time.Duration = 29 * time.Second
|
SEND_KEEPALIVE_EVERY time.Duration = 29 * time.Second
|
||||||
AUTO_RECONNECT_AFTER time.Duration = 30 * time.Second
|
AUTO_RECONNECT_AFTER time.Duration = 30 * time.Second
|
||||||
|
RECONNECT_IF_NO_DATA_RECIEVED_IN time.Duration = 24 * time.Hour // we expect keepalives wayyyy more frequently than this
|
||||||
)
|
)
|
||||||
|
|
||||||
var rx_protocolMessage *regexp.Regexp
|
var rx_protocolMessage *regexp.Regexp
|
||||||
|
Loading…
Reference in New Issue
Block a user