Skip to content

Commit

Permalink
peers: allow access to underlying connection
Browse files Browse the repository at this point in the history
This is a first iteration for @awlx. I think this does
require further investigation as I am also not very happy
with the handler interface. As soon as we try to send data
to HAProxy we do need a base implementation that tracks
sticktable ids and allows us to define new one and reference
known sticktables. This is required as we always have to send
HAProxy all sticktables we want to send updates for and can't
reference the ones we already got from that instance.
  • Loading branch information
fionera committed Aug 29, 2024
1 parent 278b6f1 commit f3fa116
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion peers/peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ func (a *Peer) Serve(l net.Listener) error {
return fmt.Errorf("accepting conn: %w", err)
}

p := newProtocolClient(a.BaseContext, nc, a.HandlerSource())
// Wrap the context to provide access to the underlying connection.
// TODO(tim): Do we really want this?
ctx := context.WithValue(a.BaseContext, connectionKey, nc)
p := newProtocolClient(ctx, nc, a.HandlerSource())
go func() {
defer nc.Close()
defer p.Close()
Expand All @@ -67,3 +70,15 @@ func (a *Peer) Serve(l net.Listener) error {
}()
}
}

type contextKey string

const (
connectionKey = contextKey("connection")
)

// Connection returns the underlying connection used in calls
// to function in a Handler.
func Connection(ctx context.Context) net.Conn {
return ctx.Value(connectionKey).(net.Conn)
}

0 comments on commit f3fa116

Please sign in to comment.