network

package
v0.0.0-...-8deeed5 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: 20 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ILimiter

type ILimiter interface {
	Wait(int, int) error
	DownLimit(int, int) error
	UpLimit(int, int) error
}

type IRequest

type IRequest interface {
	GetRequestId() string
	net.Conn
}

type Listener

type Listener struct {
	Addr    string
	Timeout time.Duration
	TCP     *net.TCPListener
	UDP     net.PacketConn
	context.Context
}
Example
listener := NewListener("127.0.0.1:1000", 5*time.Second)
listener.ListenUDP(func(request *Request) {
	for {
		buf := make([]byte, 2048)
		_, _, err := request.ReadFrom(buf)
		if err != nil {
			if strings.Contains(err.Error(), " use of closed network connection") {
				println(err.Error())
				return
			}
			log.Err(err)
		}
		log.Info(string(buf))
	}
})
listener.ListenTCP(func(request *Request) {
	buf := make([]byte, 2048)
	for {
		n, err := request.Read(buf)
		if err != nil {
			log.Err(err)
		}
		log.Info(string(buf[:n]))
	}
})
osx.WaitSignal()
println("close listener")
listener.Close()
osx.WaitSignal()
Output:

func NewListener

func NewListener(addr string, timeout time.Duration) *Listener

func (*Listener) Close

func (l *Listener) Close() error

func (*Listener) ListenTCP

func (l *Listener) ListenTCP(fn func(request *Request)) error

func (*Listener) ListenUDP

func (l *Listener) ListenUDP(fn func(request *Request)) error

type Request

type Request struct {
	ISStream bool
	net.Conn
	net.PacketConn
	RequestID   string
	RequestTime time.Time
	Data        interface{}
}

func DialTcp

func DialTcp(addr string) (req *Request, err error)

func DialUdp

func DialUdp(addr string) (req *Request, err error)

func NewRequestWithTCP

func NewRequestWithTCP(con net.Conn) *Request

func NewRequestWithUDP

func NewRequestWithUDP(con net.PacketConn) *Request

func (*Request) Close

func (r *Request) Close() error

func (*Request) GetRequestId

func (r *Request) GetRequestId() string

func (*Request) LocalAddr

func (r *Request) LocalAddr() net.Addr

func (*Request) RemoteAddr

func (r *Request) RemoteAddr() net.Addr

func (*Request) SetDeadline

func (r *Request) SetDeadline(t time.Time) error

func (*Request) SetKeepAlive

func (r *Request) SetKeepAlive(keepAlive bool) error

func (*Request) SetReadDeadline

func (r *Request) SetReadDeadline(t time.Time) error

func (*Request) SetWriteDeadline

func (r *Request) SetWriteDeadline(t time.Time) error

type ShadowsocksRDecorate

type ShadowsocksRDecorate struct {
	*Request
	UID int

	Host          string
	Port          int
	ObfsParam     string
	ProtocolParam string
	Users         map[string]string
	Overhead      int
	ISLocal       bool

	common.TrafficReport
	ILimiter
	*sync.Mutex
	// contains filtered or unexported fields
}

func NewShadowsocksRDecorate

func NewShadowsocksRDecorate(request *Request, obfsMethod, cryptMethod, key, protocolMethod, obfsParam, protocolParam, host string, port int, isLocal bool, single int, users map[string]string) (ssrd *ShadowsocksRDecorate, err error)

func (*ShadowsocksRDecorate) Read

func (ssrd *ShadowsocksRDecorate) Read(buf []byte) (n int, err error)

func (*ShadowsocksRDecorate) ReadFrom

func (ssrd *ShadowsocksRDecorate) ReadFrom() (data, uid []byte, addr net.Addr, err error)

func (*ShadowsocksRDecorate) SetLimter

func (ssrd *ShadowsocksRDecorate) SetLimter(limiter ILimiter)

func (*ShadowsocksRDecorate) UpdateUser

func (ssrd *ShadowsocksRDecorate) UpdateUser(uid []byte)

func (*ShadowsocksRDecorate) Write

func (ssrd *ShadowsocksRDecorate) Write(buf []byte) (n int, err error)

func (*ShadowsocksRDecorate) WriteTo

func (ssrd *ShadowsocksRDecorate) WriteTo(p, uid []byte, addr net.Addr) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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