portforwarding

package
v0.0.0-...-c4ad86a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2020 License: Apache-2.0 Imports: 19 Imported by: 0

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

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

type PortMappingNetworkIO struct {
	From net.Conn
	To   net.Conn
}

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

func (s *Service) DeletePortMapping(id string) error

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

func (s *Service) NewTCPPortMappingRequestHandler(portMappingRequestConnection net.Conn) error

NewTCPPortMappingRequestHandler adds a new port mapping forward handler. Create the port mapping info from the network connection.

func (*Service) RPCAddPortMapping

RPCAddPortMapping handles the adding port forwarding request from the GRPC client.

func (*Service) RPCDeletePortMapping

RPCDeletePortMapping handles the delete port mapping request.

func (*Service) RPCListPortMapping

RPCListPortMapping handles the list port mapping request.

func (*Service) SetUpstreamService

func (s *Service) SetUpstreamService(upstreamService *Service)

SetUpstreamService sets the upstream service if runs in chain mode

func (*Service) Start

func (s *Service) Start() error

Start starts the port mapping service.

func (*Service) StartGRPCServer

func (s *Service) StartGRPCServer()

StartGRPCServer start the GRPC server

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL