dchan

package
v0.0.0-...-a9387a1 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2022 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChanCount = 1
)

Variables

View Source
var (
	HttpKeyIV       = "X-Log"
	HttpKeyUserId   = "X-Host-ID"
	HttpKeyChecksum = "X-MD5"
)
View Source
var (
	ErrInvalidUserId        = logex.Define("invalid user id")
	ErrUnexpectedPacketType = logex.Define("unexpected packet type")
)

Functions

func CheckType

func CheckType(name string) error

func DialTimeout

func DialTimeout()

Types

type Channel

type Channel interface {
	Close()
	Name() string
	GetStat() *statistic.HeartBeat
	Latency() (time.Duration, time.Duration)
	GetUserId() (int, error)
	AddOnClose(func())
	GetSpeed() *statistic.SpeedInfo
	ChanWrite() packet.SendChan
	Run()

	ReadL2(*bufio.Reader) (*packet.PacketL2, error)
	WriteL2(*packet.PacketL2) []byte
}

func NewTcpChanClient

func NewTcpChanClient(f *flow.Flow, session *packet.Session, conn net.Conn, out packet.SendChan) Channel

func NewTcpChanServer

func NewTcpChanServer(f *flow.Flow, session *packet.Session, conn net.Conn, delegate SvrInitDelegate) Channel

type ChannelFactory

type ChannelFactory interface {
	NewClient(*flow.Flow, *packet.Session, net.Conn, packet.SendChan) Channel
	NewServer(*flow.Flow, *packet.Session, net.Conn, SvrInitDelegate) Channel

	Listen(f *flow.Flow) (net.Listener, error)
	DialTimeout(host string, timeout time.Duration) (net.Conn, error)
}

func GetChannelType

func GetChannelType(name string) ChannelFactory

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(f *flow.Flow,
	s *packet.Session, delegate ClientDelegate, chanTyp string,
	toDC packet.RecvChan, fromDC packet.SendChan) (*Client, error)

out is which datachannel can write for all of channel share on fromDC, and have their owned toDC client receive all packet from toDC and try to send them

func (*Client) AddHost

func (c *Client) AddHost(host string, port int)

AddHost will exclude endpoint which is already exists

func (*Client) Close

func (c *Client) Close()

func (*Client) CloseChannel

func (c *Client) CloseChannel(name string) error

func (*Client) GetFlow

func (c *Client) GetFlow() *flow.Flow

func (*Client) GetRunningChans

func (c *Client) GetRunningChans() int

func (*Client) GetSpeedInfo

func (c *Client) GetSpeedInfo() *statistic.SpeedInfo

func (*Client) GetStats

func (c *Client) GetStats() string

func (*Client) GetUsefulChan

func (c *Client) GetUsefulChan() []Channel

func (*Client) MakeNewChannel

func (c *Client) MakeNewChannel(slot Slot) error

func (*Client) Ports

func (c *Client) Ports() []int

func (*Client) Run

func (c *Client) Run()

func (*Client) UpdateRemoteAddrs

func (c *Client) UpdateRemoteAddrs(host string, ports []int)

type ClientDelegate

type ClientDelegate interface {
	OnAllBackoff(*Client)
	OnLinkRefused()
}

type Group

type Group struct {
	// contains filtered or unexported fields
}

Channel can't close by Group

func NewGroup

func NewGroup(f *flow.Flow, toDC packet.RecvChan, fromDC packet.SendChan) *Group

func (*Group) AddWithAutoRemove

func (g *Group) AddWithAutoRemove(c Channel)

func (*Group) ChannelCount

func (g *Group) ChannelCount() int

func (*Group) Close

func (g *Group) Close()

func (*Group) CloseChannel

func (g *Group) CloseChannel(name string) error

func (*Group) GetSpeed

func (g *Group) GetSpeed() *statistic.SpeedInfo

func (*Group) GetStatsInfo

func (g *Group) GetStatsInfo() string

func (*Group) GetUseful

func (g *Group) GetUseful() []int

func (*Group) GetUsefulChan

func (g *Group) GetUsefulChan() []Channel

func (*Group) Run

func (g *Group) Run()

func (*Group) Send

func (g *Group) Send(p []*packet.Packet)
type Header []header

func (*Header) Add

func (h *Header) Add(k string, v string)

func (Header) Get

func (h Header) Get(k string) string

type HttpChan

type HttpChan struct {
	// contains filtered or unexported fields
}

to simulate http interactive

func NewHttpChanClient

func NewHttpChanClient(f *flow.Flow, session *packet.Session, conn net.Conn, out packet.SendChan) *HttpChan

func NewHttpChanServer

func NewHttpChanServer(f *flow.Flow, s *packet.Session, conn net.Conn, delegate SvrInitDelegate) *HttpChan

func (*HttpChan) AddOnClose

func (h *HttpChan) AddOnClose(f func())

func (*HttpChan) ChanWrite

func (h *HttpChan) ChanWrite() packet.SendChan

func (*HttpChan) Close

func (h *HttpChan) Close()

func (*HttpChan) GetSpeed

func (h *HttpChan) GetSpeed() *statistic.SpeedInfo

func (*HttpChan) GetStat

func (h *HttpChan) GetStat() *statistic.HeartBeat

func (*HttpChan) GetUserId

func (h *HttpChan) GetUserId() (int, error)

func (*HttpChan) HeartBeatClean

func (h *HttpChan) HeartBeatClean(err error)

func (*HttpChan) IsSvrModeAndUninit

func (h *HttpChan) IsSvrModeAndUninit() bool

func (*HttpChan) Latency

func (h *HttpChan) Latency() (time.Duration, time.Duration)

func (*HttpChan) Name

func (h *HttpChan) Name() string

func (*HttpChan) ReadL2

func (h *HttpChan) ReadL2(b *bufio.Reader) (*packet.PacketL2, error)

func (*HttpChan) Run

func (h *HttpChan) Run()

func (*HttpChan) WriteL2

func (h *HttpChan) WriteL2(p *packet.PacketL2) []byte

type HttpChanFactory

type HttpChanFactory struct{}

func (HttpChanFactory) DialTimeout

func (HttpChanFactory) DialTimeout(host string, timeout time.Duration) (net.Conn, error)

func (HttpChanFactory) Listen

func (HttpChanFactory) Listen(*flow.Flow) (net.Listener, error)

func (HttpChanFactory) NewClient

func (HttpChanFactory) NewServer

type KcpChanFactory

type KcpChanFactory struct{}

type Listener

type Listener struct {
	// contains filtered or unexported fields
}

add self monitor

func NewListener

func NewListener(f *flow.Flow, d SvrDelegate, chanFactory ChannelFactory, c func()) (*Listener, error)

func (*Listener) Accept

func (d *Listener) Accept() (Channel, error)

func (*Listener) Close

func (d *Listener) Close()

func (*Listener) GetPort

func (d *Listener) GetPort() int

func (*Listener) Serve

func (d *Listener) Serve()

type ListenerGroup

type ListenerGroup struct {
	// contains filtered or unexported fields
}

func NewListenerGroup

func NewListenerGroup(f *flow.Flow, chanType string, delegate SvrDelegate) *ListenerGroup

server communicate with channel

func (*ListenerGroup) Close

func (s *ListenerGroup) Close()

func (*ListenerGroup) GetAllDataChannel

func (s *ListenerGroup) GetAllDataChannel() []int

func (*ListenerGroup) GetDataChannel

func (s *ListenerGroup) GetDataChannel() int

func (*ListenerGroup) Run

func (s *ListenerGroup) Run(n int)

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server side for operate datachannel for all user

func NewServer

func NewServer(f *flow.Flow, delegate SvrDelegate) *Server

func (*Server) AddChannel

func (s *Server) AddChannel(ch Channel) error

func (*Server) Close

func (s *Server) Close()

func (*Server) Group

func (s *Server) Group(userId int) (*Group, error)

type SimpleReq

type SimpleReq struct {
	Header Header
	Body   io.ReadCloser
}

func NewSimpleReq

func NewSimpleReq(r *bufio.Reader) (*SimpleReq, error)

type Slot

type Slot struct {
	Host string
	Port uint16
}

func (Slot) String

func (s Slot) String() string

type SvrAuthDelegate

type SvrAuthDelegate interface {
	GetUserToken(id int) ([]byte, error)
}

type SvrDelegate

type SvrDelegate interface {
	SvrAuthDelegate
	GetUserChannelFromDataChannel(id int) (
		fromUser packet.RecvChan, toUser packet.SendChan, err error)
	OnDChanUpdate([]int)
	OnNewChannel(Channel)
}

type SvrInitDelegate

type SvrInitDelegate interface {
	Init(id int) (toUser packet.SendChan, err error)
	OnInited(ch Channel)
}

type TcpChan

type TcpChan struct {
	// contains filtered or unexported fields
}

func (*TcpChan) AddOnClose

func (c *TcpChan) AddOnClose(f func())

func (*TcpChan) ChanWrite

func (c *TcpChan) ChanWrite() packet.SendChan

func (*TcpChan) Close

func (c *TcpChan) Close()

func (*TcpChan) GetSpeed

func (c *TcpChan) GetSpeed() *statistic.SpeedInfo

func (*TcpChan) GetStat

func (c *TcpChan) GetStat() *statistic.HeartBeat

func (*TcpChan) GetUserId

func (c *TcpChan) GetUserId() (int, error)

func (*TcpChan) HeartBeatClean

func (c *TcpChan) HeartBeatClean(err error)

func (*TcpChan) IsSvrModeAndUninit

func (c *TcpChan) IsSvrModeAndUninit() bool

func (*TcpChan) Latency

func (c *TcpChan) Latency() (latency, lastCommit time.Duration)

func (*TcpChan) Name

func (c *TcpChan) Name() string

func (*TcpChan) ReadL2

func (c *TcpChan) ReadL2(r *bufio.Reader) (*packet.PacketL2, error)

func (*TcpChan) Run

func (c *TcpChan) Run()

func (*TcpChan) WriteL2

func (c *TcpChan) WriteL2(p *packet.PacketL2) []byte

type TcpChanFactory

type TcpChanFactory struct{}

func (TcpChanFactory) DialTimeout

func (TcpChanFactory) DialTimeout(host string, timeout time.Duration) (net.Conn, error)

func (TcpChanFactory) Listen

func (TcpChanFactory) Listen(*flow.Flow) (net.Listener, error)

func (TcpChanFactory) NewClient

func (TcpChanFactory) NewClient(f *flow.Flow, session *packet.Session, conn net.Conn, out packet.SendChan) Channel

func (TcpChanFactory) NewServer

func (TcpChanFactory) NewServer(f *flow.Flow, session *packet.Session, conn net.Conn, delegate SvrInitDelegate) Channel

type UDPConn

type UDPConn struct {
	// contains filtered or unexported fields
}

func NewUDPConn

func NewUDPConn(f *flow.Flow, local, remote *net.UDPAddr, delegate writeDelegate) *UDPConn

func (*UDPConn) Close

func (u *UDPConn) Close() error

func (*UDPConn) LocalAddr

func (u *UDPConn) LocalAddr() net.Addr

func (*UDPConn) Read

func (u *UDPConn) Read(b []byte) (int, error)

func (*UDPConn) RemoteAddr

func (u *UDPConn) RemoteAddr() net.Addr

func (*UDPConn) SetDeadline

func (u *UDPConn) SetDeadline(d time.Time) error

func (*UDPConn) SetReadDeadline

func (u *UDPConn) SetReadDeadline(d time.Time) error

func (*UDPConn) SetWriteDeadline

func (u *UDPConn) SetWriteDeadline(d time.Time) error

func (*UDPConn) Write

func (u *UDPConn) Write(b []byte) (int, error)

func (*UDPConn) WriteChan

func (u *UDPConn) WriteChan() chan []byte

type UDPListener

type UDPListener struct {
	// contains filtered or unexported fields
}

func NewUDPListener

func NewUDPListener(f *flow.Flow, conn *net.UDPConn) *UDPListener

func (*UDPListener) Accept

func (u *UDPListener) Accept() (net.Conn, error)

func (*UDPListener) Addr

func (u *UDPListener) Addr() net.Addr

func (*UDPListener) ClientClose

func (u *UDPListener) ClientClose(addr *net.UDPAddr)

func (*UDPListener) Close

func (u *UDPListener) Close() error

func (*UDPListener) WriteToUDP

func (u *UDPListener) WriteToUDP(b []byte, addr *net.UDPAddr) (int, error)

type UdpChanFactory

type UdpChanFactory struct {
	// contains filtered or unexported fields
}

func NewUdpChanFactory

func NewUdpChanFactory() *UdpChanFactory

func (UdpChanFactory) DialTimeout

func (UdpChanFactory) DialTimeout(host string, timeout time.Duration) (net.Conn, error)

func (*UdpChanFactory) Listen

func (u *UdpChanFactory) Listen(f *flow.Flow) (net.Listener, error)

func (UdpChanFactory) NewClient

func (UdpChanFactory) NewClient(f *flow.Flow, session *packet.Session, conn net.Conn, out packet.SendChan) Channel

func (UdpChanFactory) NewServer

func (UdpChanFactory) NewServer(f *flow.Flow, session *packet.Session, conn net.Conn, delegate SvrInitDelegate) Channel

Jump to

Keyboard shortcuts

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