mr2

package module
v0.0.0-...-16e68b6 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2021 License: GPL-3.0 Imports: 15 Imported by: 0

README

Mr.2

中文

Build Status Donate Slack

What is Mr.2

Mr.2 can help you expose local server to external network. Support both TCP/UDP, of course support HTTP. Keep it simple, stupid.

Install via nami
$ nami install github.com/txthinking/mr2

or download from releases

Server
$ mr2 server -l :9999 -p password

# Only allow partial ports, and set password on each port
$ mr2 server -l :9999 -P '5678 password' -P '6789 password1'
Client
# Local server is 127.0.0.1:1234, expect to expose: server_address:5678
$ mr2 client -s server_address:port -p password -P 5678 -c 127.0.0.1:1234

# Local web root is /path/to/www, expect to expose: server_address:5678
$ mr2 client -s server_address:port -p password -P 5678 --clientDirectory /path/to/www
Example
Access local HTTP server
$ mr2 client -s server_address:port -p password -P 5678 -c 127.0.0.1:8080

# then
Your HTTP server in external network is: server_address:5678
SSH into local computer
$ mr2 client -s server_address:port -p password -P 5678 -c 127.0.0.1:22

# then
$ ssh -oPort=5678 user@server_address
Access local DNS server
$ mr2 client -s server_address:port -p password -P 5678 -c 127.0.0.1:53

# then
Your DNS server in external network is: server_address:5678

$ dig github.com @server_address -p 5678
Access your local directory via HTTP
$ mr2 client -s server_address:port -p password -P 5678 --clientDirectory /path/to/www

# then
A HTTP server in external network is: server_address:5678
Any TCP-based/UDP-based ideas you think of

...

Contributing

Please read CONTRIBUTING.md first

License

Licensed under The GPLv3 License

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidLengthMr2 = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowMr2   = fmt.Errorf("proto: integer overflow")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	Server       string
	ServerPort   int64
	ServerDomain string
	ClientServer string
	TCPDeadline  int64
	TCPTimeout   int64
	UDPDeadline  int64
	UDPConn      *net.UDPConn
	Ckv          *encrypt.KV
	TCPClient    *TCPClient
	UDPClient    *UDPClient
}

Client .

func NewClient

func NewClient(server, password string, serverPort int64, serverDomain, clientServer string, tcpTimeout, tcpDeadline, udpDeadline int64) *Client

NewClient .

func (*Client) ListenAndServe

func (c *Client) ListenAndServe() error

Run .

func (*Client) Shutdown

func (c *Client) Shutdown() error

Shutdown server.

type PingPong

type PingPong struct {
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*PingPong) Descriptor

func (*PingPong) Descriptor() ([]byte, []int)

func (*PingPong) Marshal

func (m *PingPong) Marshal() (dAtA []byte, err error)

func (*PingPong) MarshalTo

func (m *PingPong) MarshalTo(dAtA []byte) (int, error)

func (*PingPong) ProtoMessage

func (*PingPong) ProtoMessage()

func (*PingPong) Reset

func (m *PingPong) Reset()

func (*PingPong) Size

func (m *PingPong) Size() (n int)

func (*PingPong) String

func (m *PingPong) String() string

func (*PingPong) Unmarshal

func (m *PingPong) Unmarshal(dAtA []byte) error

func (*PingPong) XXX_DiscardUnknown

func (m *PingPong) XXX_DiscardUnknown()

func (*PingPong) XXX_Marshal

func (m *PingPong) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*PingPong) XXX_Merge

func (dst *PingPong) XXX_Merge(src proto.Message)

func (*PingPong) XXX_Size

func (m *PingPong) XXX_Size() int

func (*PingPong) XXX_Unmarshal

func (m *PingPong) XXX_Unmarshal(b []byte) error

type Server

type Server struct {
	TCPAddr   *net.TCPAddr
	UDPAddr   *net.UDPAddr
	TCPListen *net.TCPListener
	UDPConn   *net.UDPConn
	Cache     *cache.Cache
	Ckv       *encrypt.KV
	PortCkv   map[int64]*encrypt.KV
}

Server .

func NewServer

func NewServer(addr, password string, portPassword []string) (*Server, error)

NewServer .

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe .

func (*Server) RunTCPServer

func (s *Server) RunTCPServer() error

RunTCPServer

func (*Server) RunUDPServer

func (s *Server) RunUDPServer() error

RunUDPServer

func (*Server) Shutdown

func (s *Server) Shutdown() error

Shutdown server.

func (*Server) TCPHandle

func (s *Server) TCPHandle(c *net.TCPConn) error

TCPHandle

func (*Server) UDPHandle

func (s *Server) UDPHandle(addr *net.UDPAddr, b []byte) error

UDPHandle

type TCPClient

type TCPClient struct {
	Client  *Client
	TCPConn *net.TCPConn
	Cache   *cache.Cache
	Done    chan byte
	Data    chan []byte
	Error   chan error
}

TCPClient .

func NewTCPClient

func NewTCPClient(c *Client) (*TCPClient, error)

NewTCPClient .

func (*TCPClient) Ping

func (c *TCPClient) Ping()

Ping server .

func (*TCPClient) Read

func (c *TCPClient) Read()

Read data from server.

func (*TCPClient) Run

func (c *TCPClient) Run() error

Run .

func (*TCPClient) Stop

func (c *TCPClient) Stop()

Stop .

type TCPHello

type TCPHello struct {
	Port                 int64    `protobuf:"varint,1,opt,name=Port,proto3" json:"Port,omitempty"`
	TCPTimeout           int64    `protobuf:"varint,2,opt,name=TCPTimeout,proto3" json:"TCPTimeout,omitempty"`
	TCPDeadline          int64    `protobuf:"varint,3,opt,name=TCPDeadline,proto3" json:"TCPDeadline,omitempty"`
	Key                  string   `protobuf:"bytes,4,opt,name=Key,proto3" json:"Key,omitempty"`
	Domain               string   `protobuf:"bytes,5,opt,name=Domain,proto3" json:"Domain,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*TCPHello) Descriptor

func (*TCPHello) Descriptor() ([]byte, []int)

func (*TCPHello) GetDomain

func (m *TCPHello) GetDomain() string

func (*TCPHello) GetKey

func (m *TCPHello) GetKey() string

func (*TCPHello) GetPort

func (m *TCPHello) GetPort() int64

func (*TCPHello) GetTCPDeadline

func (m *TCPHello) GetTCPDeadline() int64

func (*TCPHello) GetTCPTimeout

func (m *TCPHello) GetTCPTimeout() int64

func (*TCPHello) Marshal

func (m *TCPHello) Marshal() (dAtA []byte, err error)

func (*TCPHello) MarshalTo

func (m *TCPHello) MarshalTo(dAtA []byte) (int, error)

func (*TCPHello) ProtoMessage

func (*TCPHello) ProtoMessage()

func (*TCPHello) Reset

func (m *TCPHello) Reset()

func (*TCPHello) Size

func (m *TCPHello) Size() (n int)

func (*TCPHello) String

func (m *TCPHello) String() string

func (*TCPHello) Unmarshal

func (m *TCPHello) Unmarshal(dAtA []byte) error

func (*TCPHello) XXX_DiscardUnknown

func (m *TCPHello) XXX_DiscardUnknown()

func (*TCPHello) XXX_Marshal

func (m *TCPHello) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*TCPHello) XXX_Merge

func (dst *TCPHello) XXX_Merge(src proto.Message)

func (*TCPHello) XXX_Size

func (m *TCPHello) XXX_Size() int

func (*TCPHello) XXX_Unmarshal

func (m *TCPHello) XXX_Unmarshal(b []byte) error

type TCPPacket

type TCPPacket struct {
	Address              string   `protobuf:"bytes,1,opt,name=Address,proto3" json:"Address,omitempty"`
	Data                 []byte   `protobuf:"bytes,2,opt,name=Data,proto3" json:"Data,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*TCPPacket) Descriptor

func (*TCPPacket) Descriptor() ([]byte, []int)

func (*TCPPacket) GetAddress

func (m *TCPPacket) GetAddress() string

func (*TCPPacket) GetData

func (m *TCPPacket) GetData() []byte

func (*TCPPacket) Marshal

func (m *TCPPacket) Marshal() (dAtA []byte, err error)

func (*TCPPacket) MarshalTo

func (m *TCPPacket) MarshalTo(dAtA []byte) (int, error)

func (*TCPPacket) ProtoMessage

func (*TCPPacket) ProtoMessage()

func (*TCPPacket) Reset

func (m *TCPPacket) Reset()

func (*TCPPacket) Size

func (m *TCPPacket) Size() (n int)

func (*TCPPacket) String

func (m *TCPPacket) String() string

func (*TCPPacket) Unmarshal

func (m *TCPPacket) Unmarshal(dAtA []byte) error

func (*TCPPacket) XXX_DiscardUnknown

func (m *TCPPacket) XXX_DiscardUnknown()

func (*TCPPacket) XXX_Marshal

func (m *TCPPacket) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*TCPPacket) XXX_Merge

func (dst *TCPPacket) XXX_Merge(src proto.Message)

func (*TCPPacket) XXX_Size

func (m *TCPPacket) XXX_Size() int

func (*TCPPacket) XXX_Unmarshal

func (m *TCPPacket) XXX_Unmarshal(b []byte) error

type TCPServer

type TCPServer struct {
	Server      *Server
	Cache       *cache.Cache
	TCPConn     *net.TCPConn
	TCPListen   *net.TCPListener
	TCPTimeout  int64
	TCPDeadline int64
	Done        chan byte
	Data        chan []byte
	Error       chan error
}

TCPServer .

func NewTCPServer

func NewTCPServer(s *Server, c *net.TCPConn) (*TCPServer, error)

NewTCPServer. Some cases return nil, nil

func (*TCPServer) Accept

func (s *TCPServer) Accept()

Accept consumer.

func (*TCPServer) ListenAndServe

func (s *TCPServer) ListenAndServe() error

ListenAndServe .

func (*TCPServer) Read

func (s *TCPServer) Read()

Read data from client.

func (*TCPServer) Shutdown

func (s *TCPServer) Shutdown()

Shutdown .

type UDPClient

type UDPClient struct {
	Client  *Client
	UDPConn *net.UDPConn
	Cache   *cache.Cache
	Done    chan byte
	Data    chan []byte
	Error   chan error
}

UDPClient .

func NewUDPClient

func NewUDPClient(c *Client) (*UDPClient, error)

NewUDPClient .

func (*UDPClient) Ping

func (c *UDPClient) Ping()

Ping server .

func (*UDPClient) Read

func (c *UDPClient) Read()

Read data from server.

func (*UDPClient) Run

func (c *UDPClient) Run() error

Run .

func (*UDPClient) Stop

func (c *UDPClient) Stop()

Stop .

type UDPPacket

type UDPPacket struct {
	Port                 int64    `protobuf:"varint,1,opt,name=Port,proto3" json:"Port,omitempty"`
	Address              string   `protobuf:"bytes,2,opt,name=Address,proto3" json:"Address,omitempty"`
	Data                 []byte   `protobuf:"bytes,3,opt,name=Data,proto3" json:"Data,omitempty"`
	Key                  string   `protobuf:"bytes,4,opt,name=Key,proto3" json:"Key,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*UDPPacket) Descriptor

func (*UDPPacket) Descriptor() ([]byte, []int)

func (*UDPPacket) GetAddress

func (m *UDPPacket) GetAddress() string

func (*UDPPacket) GetData

func (m *UDPPacket) GetData() []byte

func (*UDPPacket) GetKey

func (m *UDPPacket) GetKey() string

func (*UDPPacket) GetPort

func (m *UDPPacket) GetPort() int64

func (*UDPPacket) Marshal

func (m *UDPPacket) Marshal() (dAtA []byte, err error)

func (*UDPPacket) MarshalTo

func (m *UDPPacket) MarshalTo(dAtA []byte) (int, error)

func (*UDPPacket) ProtoMessage

func (*UDPPacket) ProtoMessage()

func (*UDPPacket) Reset

func (m *UDPPacket) Reset()

func (*UDPPacket) Size

func (m *UDPPacket) Size() (n int)

func (*UDPPacket) String

func (m *UDPPacket) String() string

func (*UDPPacket) Unmarshal

func (m *UDPPacket) Unmarshal(dAtA []byte) error

func (*UDPPacket) XXX_DiscardUnknown

func (m *UDPPacket) XXX_DiscardUnknown()

func (*UDPPacket) XXX_Marshal

func (m *UDPPacket) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*UDPPacket) XXX_Merge

func (dst *UDPPacket) XXX_Merge(src proto.Message)

func (*UDPPacket) XXX_Size

func (m *UDPPacket) XXX_Size() int

func (*UDPPacket) XXX_Unmarshal

func (m *UDPPacket) XXX_Unmarshal(b []byte) error

type UDPServer

type UDPServer struct {
	Server  *Server
	UDPConn *net.UDPConn
	Addr    *net.UDPAddr
}

UDPServer .

func NewUDPServer

func NewUDPServer(s *Server, p *UDPPacket, addr *net.UDPAddr) (*UDPServer, error)

NewUDPServer .

func (*UDPServer) HandlePacket

func (s *UDPServer) HandlePacket(p *UDPPacket) error

HandlePacket sends data to consumer.

func (*UDPServer) ListenAndServe

func (s *UDPServer) ListenAndServe() error

ListenAndServe .

func (*UDPServer) Shutdown

func (s *UDPServer) Shutdown()

Shutdown .

Directories

Path Synopsis
cli
mr2

Jump to

Keyboard shortcuts

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