Merge pull request #1105 from yggdrasil-network/neil/backoff

Tweak backoff success handling
This commit is contained in:
Arceliar 2023-11-21 04:49:41 -06:00 committed by GitHub
commit abec2256ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -249,6 +249,12 @@ func (l *links) add(u *url.URL, sintf string, linkType linkType) error {
} }
} }
// resetBackoff is called by the connection handler when the
// handshake has successfully completed.
resetBackoff := func() {
backoff = 0
}
// The goroutine is responsible for attempting the connection // The goroutine is responsible for attempting the connection
// and then running the handler. If the connection is persistent // and then running the handler. If the connection is persistent
// then the loop will run endlessly, using backoffs as needed. // then the loop will run endlessly, using backoffs as needed.
@ -325,10 +331,8 @@ func (l *links) add(u *url.URL, sintf string, linkType linkType) error {
// Give the connection to the handler. The handler will block // Give the connection to the handler. The handler will block
// for the lifetime of the connection. // for the lifetime of the connection.
if err = l.handler(linkType, options, lc); err != nil && err != io.EOF { if err = l.handler(linkType, options, lc, resetBackoff); err != nil && err != io.EOF {
l.core.log.Debugf("Link %s error: %s\n", info.uri, err) l.core.log.Debugf("Link %s error: %s\n", info.uri, err)
} else {
backoff = 0
} }
// The handler has stopped running so the connection is dead, // The handler has stopped running so the connection is dead,
@ -491,7 +495,7 @@ func (l *links) listen(u *url.URL, sintf string) (*Listener, error) {
// Give the connection to the handler. The handler will block // Give the connection to the handler. The handler will block
// for the lifetime of the connection. // for the lifetime of the connection.
if err = l.handler(linkTypeIncoming, options, lc); err != nil && err != io.EOF { if err = l.handler(linkTypeIncoming, options, lc, nil); err != nil && err != io.EOF {
l.core.log.Debugf("Link %s error: %s\n", u.Host, err) l.core.log.Debugf("Link %s error: %s\n", u.Host, err)
} }
@ -529,7 +533,7 @@ func (l *links) connect(ctx context.Context, u *url.URL, info linkInfo, options
return dialer.dial(ctx, u, info, options) return dialer.dial(ctx, u, info, options)
} }
func (l *links) handler(linkType linkType, options linkOptions, conn net.Conn) error { func (l *links) handler(linkType linkType, options linkOptions, conn net.Conn, success func()) error {
meta := version_getBaseMetadata() meta := version_getBaseMetadata()
meta.publicKey = l.core.public meta.publicKey = l.core.public
meta.priority = options.priority meta.priority = options.priority
@ -600,6 +604,9 @@ func (l *links) handler(linkType linkType, options linkOptions, conn net.Conn) e
} }
l.core.log.Infof("Connected %s: %s, source %s", l.core.log.Infof("Connected %s: %s, source %s",
dir, remoteStr, localStr) dir, remoteStr, localStr)
if success != nil {
success()
}
err = l.core.HandleConn(meta.publicKey, conn, priority) err = l.core.HandleConn(meta.publicKey, conn, priority)
switch err { switch err {