Skip to content

Commit

Permalink
Add peer infomation to http2server context.
Browse files Browse the repository at this point in the history
  • Loading branch information
feihu-stripe committed Aug 16, 2022
1 parent 3f5b7ab commit dde7635
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions internal/transport/http2_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ func NewServerTransport(conn net.Conn, config *ServerConfig) (_ ServerTransport,
czData: new(channelzData),
bufferPool: newBufferPool(),
}
// Add peer information to the http2server context.
t.ctx = peer.NewContext(t.ctx, t.getPeer())

t.controlBuf = newControlBuffer(t.done)
if dynamicWindow {
t.bdpEst = &bdpEstimator{
Expand Down Expand Up @@ -485,14 +488,10 @@ func (t *http2Server) operateHeaders(frame *http2.MetaHeadersFrame, handle func(
} else {
s.ctx, s.cancel = context.WithCancel(t.ctx)
}
pr := &peer.Peer{
Addr: t.remoteAddr,
}
// Attach Auth info if there is any.
if t.authInfo != nil {
pr.AuthInfo = t.authInfo
}
s.ctx = peer.NewContext(s.ctx, pr)

// Add peer information to the stream context.
s.ctx = peer.NewContext(s.ctx, t.getPeer())

// Attach the received metadata to the context.
if len(mdata) > 0 {
s.ctx = metadata.NewIncomingContext(s.ctx, mdata)
Expand Down Expand Up @@ -1416,6 +1415,17 @@ func (t *http2Server) getOutFlowWindow() int64 {
}
}

func (t *http2Server) getPeer() *peer.Peer {
pr := &peer.Peer{
Addr: t.remoteAddr,
}
// Attach Auth info if there is any.
if t.authInfo != nil {
pr.AuthInfo = t.authInfo
}
return pr
}

func getJitter(v time.Duration) time.Duration {
if v == infinity {
return 0
Expand Down

0 comments on commit dde7635

Please sign in to comment.