github.com/0xsequence/ethkit@v1.25.0/go-ethereum/rpc/server.go (about)

     1  package rpc
     2  
     3  import (
     4  	"context"
     5  )
     6  
     7  // PeerInfo contains information about the remote end of the network connection.
     8  //
     9  // This is available within RPC method handlers through the context. Call
    10  // PeerInfoFromContext to get information about the client connection related to
    11  // the current method call.
    12  type PeerInfo struct {
    13      // Transport is name of the protocol used by the client.
    14      // This can be "http", "ws" or "ipc".
    15      Transport string
    16  
    17      // Address of client. This will usually contain the IP address and port.
    18      RemoteAddr string
    19  
    20      // Additional information for HTTP and WebSocket connections.
    21      HTTP struct {
    22          // Protocol version, i.e. "HTTP/1.1". This is not set for WebSocket.
    23          Version string
    24          // Header values sent by the client.
    25          UserAgent string
    26          Origin    string
    27          Host      string
    28      }
    29  }
    30  
    31  type peerInfoContextKey struct{}
    32  
    33  // PeerInfoFromContext returns information about the client's network connection.
    34  // Use this with the context passed to RPC method handler functions.
    35  //
    36  // The zero value is returned if no connection info is present in ctx.
    37  func PeerInfoFromContext(ctx context.Context) PeerInfo {
    38      info, _ := ctx.Value(peerInfoContextKey{}).(PeerInfo)
    39      return info
    40  }