Skip to content

Commit

Permalink
Added calloption to retrieve peer information
Browse files Browse the repository at this point in the history
  • Loading branch information
MakMukhi committed Feb 7, 2017
1 parent 21f8ed3 commit 794873f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions call.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"golang.org/x/net/context"
"golang.org/x/net/trace"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/peer"
"google.golang.org/grpc/stats"
"google.golang.org/grpc/transport"
)
Expand Down Expand Up @@ -85,6 +86,9 @@ func recvResponse(ctx context.Context, dopts dialOptions, t transport.ClientTran
dopts.copts.StatsHandler.HandleRPC(ctx, inPayload)
}
c.trailerMD = stream.Trailer()
if peer, ok := peer.FromContext(stream.Context()); ok {
c.peer = *peer
}
return nil
}

Expand Down
9 changes: 9 additions & 0 deletions rpc_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import (
"golang.org/x/net/context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/peer"
"google.golang.org/grpc/stats"
"google.golang.org/grpc/transport"
)
Expand Down Expand Up @@ -141,6 +142,7 @@ type callInfo struct {
headerMD metadata.MD
trailerMD metadata.MD
traceInfo traceInfo // in trace.go
peer peer.Peer
}

var defaultCallInfo = callInfo{failFast: true}
Expand Down Expand Up @@ -183,6 +185,13 @@ func Trailer(md *metadata.MD) CallOption {
})
}

// Peer returns a CallOption that retrieves peer information.
func Peer(peer *peer.Peer) CallOption {
return afterCall(func(c *callInfo) {
*peer = c.peer
})
}

// FailFast configures the action to take when an RPC is attempted on broken
// connections or unreachable servers. If failfast is true, the RPC will fail
// immediately. Otherwise, the RPC client will block the call until a
Expand Down

0 comments on commit 794873f

Please sign in to comment.