Documentation
¶
Overview ¶
Package portforwarding is a package to handle port forwarding.
request on macOS host --> port mapping service client -> port mapping service server -> destination
Index ¶
- type Client
- type NetworkEndpoint
- type PortMapping
- type PortMappingAgentClient
- type PortMappingNetworkIO
- type PortMappingServiceMode
- type PortMappingTable
- type RemoteForwardingProxyMode
- type Service
- func (s *Service) AddPortMapping(newPortMappingItem PortMapping) (string, error)
- func (s *Service) DeletePortMapping(id string) error
- func (s *Service) InitGRPCClient()
- func (s *Service) LookupPortMapping(portMappingConnection net.Conn) *PortMapping
- func (s *Service) NewTCPPortMappingRequestHandler(portMappingRequestConnection net.Conn) error
- func (s *Service) RPCAddPortMapping(ctx context.Context, req *portforwardingserverpb.CreatePortMappingRequst) (*portforwardingserverpb.CreatePortMappingResponse, error)
- func (s *Service) RPCDeletePortMapping(ctx context.Context, req *portforwardingserverpb.DeletePortMappingRequest) (*portforwardingserverpb.DeletePortMappingResponse, error)
- func (s *Service) RPCListPortMapping(ctx context.Context, req *portforwardingserverpb.ListPortMappingsRequest) (*portforwardingserverpb.ListContainersResponse, error)
- func (s *Service) SetUpstreamService(upstreamService *Service)
- func (s *Service) Start() error
- func (s *Service) StartGRPCServer()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
TargetServer NetworkEndpoint
}
Client defines the clinet config for the port mapping service. Internally its proxy + port mapping functions.
type NetworkEndpoint ¶
type NetworkEndpoint struct { IP string `json:"ip"` Port string `json:"port"` Protocol string `json:"protocol"` }
NetworkEndpoint describes the communication endpoint in a TCP/IP network.
func (*NetworkEndpoint) Description ¶
func (point *NetworkEndpoint) Description() string
Description returns a debug string of the network point.
func (*NetworkEndpoint) ListenAddress ¶
func (point *NetworkEndpoint) ListenAddress() string
ListenAddress returns a string of listen address.
type PortMapping ¶
type PortMapping struct { ID string `json:"id"` Source NetworkEndpoint `json:"source"` Target NetworkEndpoint `json:"target"` Protocol string `json:"protocol"` Description string `json:"description"` }
PortMapping defins the port mapping information
type PortMappingAgentClient ¶
type PortMappingAgentClient struct { portforwardingserverpb.PortMappingServiceClient // contains filtered or unexported fields }
PortMappingAgentClient defines the agent client of the port mapping service.
func NewPortMappingServiceClient ¶
func NewPortMappingServiceClient(portMappingGRPCServerEndpoint NetworkEndpoint) (*PortMappingAgentClient, error)
NewPortMappingServiceClient creates a client of the GRPC service.
func (*PortMappingAgentClient) Close ¶
func (c *PortMappingAgentClient) Close()
Close closes the client GRPC connection.
type PortMappingNetworkIO ¶
PortMappingNetworkIO defines a connection for port mapping.
func NewPortMappingNetworkIO ¶
func NewPortMappingNetworkIO(from, to net.Conn) *PortMappingNetworkIO
NewPortMappingNetworkIO create a port mapping io representation.
func (*PortMappingNetworkIO) Connect ¶
func (portMappingIO *PortMappingNetworkIO) Connect()
Connect connect two network io
type PortMappingServiceMode ¶
type PortMappingServiceMode string
PortMappingServiceMode runs the port mapping service locally or remotely.
const ( // PortMappingServiceModeLocal runs the port mapping service on locally. PortMappingServiceModeLocal PortMappingServiceMode = "local" // PortMappingServiceModeRemote runs the port mapping service as a relay port mapping server. PortMappingServiceModeRemote PortMappingServiceMode = "remote" // PortMappingServiceModeChain runs the port mapping service on locally but enabling the chaining. PortMappingServiceModeChain PortMappingServiceMode = "chain" )
type PortMappingTable ¶
type PortMappingTable struct {
PortMappings []*PortMapping
}
PortMappingTable defines a list of port mapping.
type RemoteForwardingProxyMode ¶
type RemoteForwardingProxyMode string
RemoteForwardingProxyMode in which tunnel the port mapping request is transferred.
const ( // RemoteForwardingProxyModeHTTP sends the request using the HTTP RemoteForwardingProxyModeHTTP RemoteForwardingProxyMode = "http" // RemoteForwardingProxyModeGRPC sends the request using the GRPC RemoteForwardingProxyModeGRPC RemoteForwardingProxyMode = "grpc" )
type Service ¶
type Service struct { // Handle the port mapping TCP network traffic. // for remote PortMappingListenTCPEndpoint *NetworkEndpoint // Handle the port mapping UDP network traffic. // for remote PortMappingListenUDPEndpoint *NetworkEndpoint // Handle the port mapping config request. // TODO: for performance, it's a RPC server in the future. // WebServerListenEndpoint NetworkEndpoint // GRPC port mapping service endpoint GRPCServerListenEndpoint *NetworkEndpoint // default implementation of the agent server for port mapping service. portforwardingserverpb.UnimplementedPortMappingServiceServer PortMappingTable RunningPortMappingServiceStopChannels map[string]chan struct{} PortMappingTableMutex sync.Mutex RemoteForwardingProxyMode // usefaul for chain mode + grpc proxy mode. // *PortMappingAgentClient // contains filtered or unexported fields }
Service defines the service config for the port mapping service.
func NewService ¶
func NewService(tcpLocalAddress *NetworkEndpoint, udpLocalAddress *NetworkEndpoint, grpcTCPAdress *NetworkEndpoint, webServerLocalAddress NetworkEndpoint, runMode PortMappingServiceMode) *Service
NewService creates a port mapping service representation.
func (*Service) AddPortMapping ¶
func (s *Service) AddPortMapping(newPortMappingItem PortMapping) (string, error)
AddPortMapping adding a port mapping to the store, and start the port mapping service.
func (*Service) DeletePortMapping ¶
DeletePortMapping deletes a port mapping and stop service.
func (*Service) InitGRPCClient ¶
func (s *Service) InitGRPCClient()
InitGRPCClient inits a grpc client for port mapping
func (*Service) LookupPortMapping ¶
func (s *Service) LookupPortMapping(portMappingConnection net.Conn) *PortMapping
LookupPortMapping returns a port mapping from a connection.
func (*Service) NewTCPPortMappingRequestHandler ¶
NewTCPPortMappingRequestHandler adds a new port mapping forward handler. Create the port mapping info from the network connection.
func (*Service) RPCAddPortMapping ¶
func (s *Service) RPCAddPortMapping(ctx context.Context, req *portforwardingserverpb.CreatePortMappingRequst) (*portforwardingserverpb.CreatePortMappingResponse, error)
RPCAddPortMapping handles the adding port forwarding request from the GRPC client.
func (*Service) RPCDeletePortMapping ¶
func (s *Service) RPCDeletePortMapping(ctx context.Context, req *portforwardingserverpb.DeletePortMappingRequest) (*portforwardingserverpb.DeletePortMappingResponse, error)
RPCDeletePortMapping handles the delete port mapping request.
func (*Service) RPCListPortMapping ¶
func (s *Service) RPCListPortMapping(ctx context.Context, req *portforwardingserverpb.ListPortMappingsRequest) (*portforwardingserverpb.ListContainersResponse, error)
RPCListPortMapping handles the list port mapping request.
func (*Service) SetUpstreamService ¶
SetUpstreamService sets the upstream service if runs in chain mode
func (*Service) StartGRPCServer ¶
func (s *Service) StartGRPCServer()
StartGRPCServer start the GRPC server