Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak backoff success handling #1105

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/core/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
// and then running the handler. If the connection is persistent
// then the loop will run endlessly, using backoffs as needed.
Expand Down Expand Up @@ -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
// 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)
} else {
backoff = 0
}

// The handler has stopped running so the connection is dead,
Expand Down Expand Up @@ -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
// 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)
}

Expand Down Expand Up @@ -529,7 +533,7 @@ func (l *links) connect(ctx context.Context, u *url.URL, info linkInfo, 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.publicKey = l.core.public
meta.priority = options.priority
Expand Down Expand Up @@ -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",
dir, remoteStr, localStr)
if success != nil {
success()
}

err = l.core.HandleConn(meta.publicKey, conn, priority)
switch err {
Expand Down