adc

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: May 5, 2019 License: BSD-3-Clause Imports: 21 Imported by: 1

Documentation

Index

Constants

View Source
const (
	Success     = Severity(0)
	Recoverable = Severity(1)
	Fatal       = Severity(2)
)
View Source
const (
	CategoryHub      = Category(1)
	CategoryUser     = Category(2)
	CategorySearch   = Category(4)
	CategoryFileList = Category(8)
)
View Source
const (
	ProtoADC  = `ADC/1.0`
	ProtoADCS = `ADCS/0.10`

	SchemaADC  = "adc"
	SchemaADCS = "adcs"
)
View Source
const (
	FileListBZIP = "files.xml.bz2"
)

Variables

View Source
var (
	// FeaBASE indicates base ADC protocol support.
	//
	// See: https://adc.dcbase.org/Protocol, http://adc.sourceforge.net/ADC.html
	FeaBASE = Feature{'B', 'A', 'S', 'E'}
	FeaBAS0 = Feature{'B', 'A', 'S', '0'} // TODO: clarify

	FeaTIGR = Feature{'T', 'I', 'G', 'R'} // Tiger hash support
	FeaPING = Feature{'P', 'I', 'N', 'G'} // Send additional field in hub's info message

	FeaBZIP = Feature{'B', 'Z', 'I', 'P'} // bzip2 compression of filelist, adds virtual files.xml.bz2 file
	FeaTS   = Feature{'T', 'S', '0', '0'} // Unix timestamps in messages
	FeaZLIF = Feature{'Z', 'L', 'I', 'F'} // Compressed communication (Full), adds ZON

	FeaSEGA = Feature{'S', 'E', 'G', 'A'} // Grouping of file extensions in search
	FeaUCMD = Feature{'U', 'C', 'M', 'D'} // User commands
	FeaUCM0 = Feature{'U', 'C', 'M', '0'} // User commands
	FeaADCS = Feature{'A', 'D', 'C', 'S'} // ADC over TLS for C-H

	FeaADC0 = Feature{'A', 'D', 'C', '0'} // ADC over TLS for C-C

	// FeaTCP4 should be set in user's INF to indicate that the client has an open TCP4 port (is active).
	FeaTCP4 = Feature{'T', 'C', 'P', '4'}
	// FeaTCP6 should be set in user's INF to indicate that the client has an open TCP6 port (is active).
	FeaTCP6 = Feature{'T', 'C', 'P', '6'}
)
View Source
var (
	Debug bool
)

Functions

func Marshal

func Marshal(o interface{}) ([]byte, error)

func MustMarshal

func MustMarshal(o interface{}) []byte

func RegisterMessage

func RegisterMessage(m Message)

func Unmarshal

func Unmarshal(s []byte, o interface{}) error

Types

type AddFeatures

type AddFeatures []string

func (AddFeatures) MarshalAdc

func (f AddFeatures) MarshalAdc() (string, error)

type AwayType

type AwayType int
const (
	AwayTypeNone     AwayType = 0
	AwayTypeNormal   AwayType = 1
	AwayTypeExtended AwayType = 2
)

type BasePacket

type BasePacket struct {
	Name MsgType
	Data []byte
}

func (BasePacket) Decode

func (p BasePacket) Decode() (Message, error)

func (BasePacket) Message

func (p BasePacket) Message() RawMessage

func (*BasePacket) SetMessage

func (p *BasePacket) SetMessage(m RawMessage)

type BoolInt

type BoolInt bool

func (BoolInt) MarshalAdc

func (f BoolInt) MarshalAdc() ([]byte, error)

func (*BoolInt) UnmarshalAdc

func (f *BoolInt) UnmarshalAdc(s []byte) error

type BroadcastPacket

type BroadcastPacket struct {
	BasePacket
	ID SID
}

func (*BroadcastPacket) Kind added in v0.16.4

func (*BroadcastPacket) Kind() byte

func (*BroadcastPacket) MarshalPacket

func (p *BroadcastPacket) MarshalPacket() ([]byte, error)

func (*BroadcastPacket) Source

func (p *BroadcastPacket) Source() SID

func (*BroadcastPacket) UnmarshalPacket

func (p *BroadcastPacket) UnmarshalPacket(name MsgType, data []byte) error

type CID

type CID = types.CID

type Category

type Category int

type ChatMessage

type ChatMessage struct {
	Text string `adc:"#"`
	PM   *SID   `adc:"PM"`
	Me   bool   `adc:"ME"`
	TS   int64  `adc:"TS"`
}

func (ChatMessage) Cmd

func (ChatMessage) Cmd() MsgType

type ClientPacket

type ClientPacket struct {
	BasePacket
}

func (*ClientPacket) Kind added in v0.16.4

func (*ClientPacket) Kind() byte

func (*ClientPacket) MarshalPacket

func (p *ClientPacket) MarshalPacket() ([]byte, error)

func (*ClientPacket) UnmarshalPacket

func (p *ClientPacket) UnmarshalPacket(name MsgType, data []byte) error

type Conn

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

Conn is an ADC protocol connection.

func Dial

func Dial(addr string) (*Conn, error)

Dial connects to a specified address.

func DialContext

func DialContext(ctx context.Context, addr string) (*Conn, error)

DialContext connects to a specified address.

func NewConn

func NewConn(conn net.Conn) (*Conn, error)

NewConn runs an ADC protocol over a specified connection.

func (*Conn) Broadcast

func (c *Conn) Broadcast(from SID) Route

func (*Conn) Close

func (c *Conn) Close() error

Close closes the connection.

func (*Conn) Direct

func (c *Conn) Direct(from, to SID) Route

func (*Conn) Flush

func (c *Conn) Flush() error

Flush the underlying buffer. Should be called after each WritePacket batch.

func (*Conn) LocalAddr

func (c *Conn) LocalAddr() net.Addr

func (*Conn) OnLineR added in v0.16.4

func (c *Conn) OnLineR(fnc func(line []byte) (bool, error))

func (*Conn) OnLineW added in v0.16.4

func (c *Conn) OnLineW(fnc func(line []byte) (bool, error))

func (*Conn) ReadClientMsg

func (c *Conn) ReadClientMsg(deadline time.Time) (Message, error)

func (*Conn) ReadInfoMsg

func (c *Conn) ReadInfoMsg(deadline time.Time) (Message, error)

func (*Conn) ReadPacket

func (c *Conn) ReadPacket(deadline time.Time) (Packet, error)

ReadPacket reads and decodes a single ADC command.

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() net.Addr

func (*Conn) SetWriteDeadline added in v0.16.4

func (c *Conn) SetWriteDeadline(t time.Time) error

func (*Conn) SetWriteTimeout added in v0.16.4

func (c *Conn) SetWriteTimeout(dt time.Duration)

func (*Conn) WriteBroadcast

func (c *Conn) WriteBroadcast(id SID, msg Message) error

func (*Conn) WriteClientMsg

func (c *Conn) WriteClientMsg(msg Message) error

func (*Conn) WriteDirect

func (c *Conn) WriteDirect(id, targ SID, msg Message) error

func (*Conn) WriteEcho

func (c *Conn) WriteEcho(id, targ SID, msg Message) error

func (*Conn) WriteHubMsg

func (c *Conn) WriteHubMsg(msg Message) error

func (*Conn) WriteInfoMsg

func (c *Conn) WriteInfoMsg(msg Message) error

func (*Conn) WriteKeepAlive added in v0.16.4

func (c *Conn) WriteKeepAlive() error

func (*Conn) WritePacket

func (c *Conn) WritePacket(p Packet) error

func (*Conn) ZOn added in v0.18.0

func (c *Conn) ZOn(lvl int) error

type ConnectRequest

type ConnectRequest struct {
	Proto string `adc:"#"`
	Port  int    `adc:"#"`
	Token string `adc:"#"`
}

func (ConnectRequest) Cmd

func (ConnectRequest) Cmd() MsgType

type DirectPacket

type DirectPacket struct {
	BasePacket
	ID   SID
	Targ SID
}

func (DirectPacket) Kind added in v0.16.4

func (DirectPacket) Kind() byte

func (DirectPacket) MarshalPacket

func (p DirectPacket) MarshalPacket() ([]byte, error)

func (*DirectPacket) Source

func (p *DirectPacket) Source() SID

func (*DirectPacket) Target

func (p *DirectPacket) Target() SID

func (*DirectPacket) UnmarshalPacket

func (p *DirectPacket) UnmarshalPacket(name MsgType, data []byte) error

type Disconnect

type Disconnect struct {
	ID       SID    `adc:"#"`
	Message  string `adc:"MS"`
	By       SID    `adc:"ID"`
	Duration int    `adc:"TL"`
	Redirect string `adc:"RD"`
}

func (Disconnect) Cmd

func (Disconnect) Cmd() MsgType

type EchoPacket

type EchoPacket DirectPacket

func (*EchoPacket) Kind added in v0.16.4

func (*EchoPacket) Kind() byte

func (*EchoPacket) MarshalPacket

func (p *EchoPacket) MarshalPacket() ([]byte, error)

func (*EchoPacket) Source

func (p *EchoPacket) Source() SID

func (*EchoPacket) Target

func (p *EchoPacket) Target() SID

func (*EchoPacket) UnmarshalPacket

func (p *EchoPacket) UnmarshalPacket(name MsgType, data []byte) error

type Error

type Error struct {
	Status
}

func (Error) Error

func (e Error) Error() string

type ExtFeatures

type ExtFeatures []Feature

func (ExtFeatures) Has

func (f ExtFeatures) Has(s Feature) bool

func (ExtFeatures) MarshalAdc

func (f ExtFeatures) MarshalAdc() ([]byte, error)

func (*ExtFeatures) UnmarshalAdc

func (f *ExtFeatures) UnmarshalAdc(s []byte) error

type ExtGroup

type ExtGroup int
const (
	ExtNone  ExtGroup = 0x00
	ExtAudio ExtGroup = 0x01
	ExtArch  ExtGroup = 0x02
	ExtDoc   ExtGroup = 0x04
	ExtExe   ExtGroup = 0x08
	ExtImage ExtGroup = 0x10
	ExtVideo ExtGroup = 0x20
)

func (ExtGroup) Has

func (t ExtGroup) Has(st ExtGroup) bool

func (ExtGroup) Matches

func (t ExtGroup) Matches(ext string) bool

type Feature

type Feature [4]byte

func (Feature) MarshalAdc

func (f Feature) MarshalAdc() ([]byte, error)

func (Feature) String

func (f Feature) String() string

func (*Feature) UnmarshalAdc

func (f *Feature) UnmarshalAdc(s []byte) error

type FeaturePacket

type FeaturePacket struct {
	BasePacket
	ID       SID
	Features map[Feature]bool
}

func (*FeaturePacket) Kind added in v0.16.4

func (*FeaturePacket) Kind() byte

func (*FeaturePacket) MarshalPacket

func (p *FeaturePacket) MarshalPacket() ([]byte, error)

func (*FeaturePacket) Source

func (p *FeaturePacket) Source() SID

func (*FeaturePacket) UnmarshalPacket

func (p *FeaturePacket) UnmarshalPacket(name MsgType, data []byte) error

type FileType

type FileType int
const (
	FileTypeAny  FileType = 0
	FileTypeFile FileType = 1
	FileTypeDir  FileType = 2
)

type GetInfoRequest

type GetInfoRequest struct {
	Type string `adc:"#"`
	Path string `adc:"#"`
}

func (GetInfoRequest) Cmd

func (GetInfoRequest) Cmd() MsgType

type GetPassword

type GetPassword struct {
	Salt []byte
}

func (GetPassword) Cmd

func (GetPassword) Cmd() MsgType

func (GetPassword) MarshalAdc

func (m GetPassword) MarshalAdc() ([]byte, error)

func (*GetPassword) UnmarshalAdc

func (m *GetPassword) UnmarshalAdc(data []byte) error

type GetRequest

type GetRequest struct {
	Type  string `adc:"#"`
	Path  string `adc:"#"`
	Start int64  `adc:"#"`
	Bytes int64  `adc:"#"`
}

func (GetRequest) Cmd

func (GetRequest) Cmd() MsgType

type GetResponse

type GetResponse GetRequest

func (GetResponse) Cmd

func (GetResponse) Cmd() MsgType

type HubInfo

type HubInfo struct {
	Name        string   `adc:"NI,req"`
	Version     string   `adc:"VE,req"`
	Application string   `adc:"AP"`
	Desc        string   `adc:"DE"`
	Type        UserType `adc:"CT"`

	Address    string `adc:"HH"` // Hub Host address (ADC/ADCS URL address form)
	Website    string `adc:"WS"` // Hub Website
	Network    string `adc:"NE"` // Hub Network
	Owner      string `adc:"OW"` // Hub Owner name
	Users      int    `adc:"UC"` // Current User count, required
	Share      int    `adc:"SS"` // Total share size
	Files      int    `adc:"SF"` // Total files shared
	MinShare   int    `adc:"MS"` // Minimum share required to enter hub ( bytes )
	MaxShare   int64  `adc:"XS"` // Maximum share for entering hub ( bytes )
	MinSlots   int    `adc:"ML"` // Minimum slots required to enter hub
	MaxSlots   int    `adc:"XL"` // Maximum slots for entering hub
	UsersLimit int    `adc:"MC"` // Maximum possible clients ( users ) who can connect
	Uptime     int    `adc:"UP"` // Hub uptime (seconds)

}

func (HubInfo) Cmd

func (HubInfo) Cmd() MsgType

type HubPacket

type HubPacket struct {
	BasePacket
}

func (*HubPacket) Kind added in v0.16.4

func (*HubPacket) Kind() byte

func (*HubPacket) MarshalPacket

func (p *HubPacket) MarshalPacket() ([]byte, error)

func (*HubPacket) UnmarshalPacket

func (p *HubPacket) UnmarshalPacket(name MsgType, data []byte) error

type InfoPacket

type InfoPacket struct {
	BasePacket
}

func (*InfoPacket) Kind added in v0.16.4

func (*InfoPacket) Kind() byte

func (*InfoPacket) MarshalPacket

func (p *InfoPacket) MarshalPacket() ([]byte, error)

func (*InfoPacket) UnmarshalPacket

func (p *InfoPacket) UnmarshalPacket(name MsgType, data []byte) error

type Marshaler

type Marshaler interface {
	MarshalAdc() ([]byte, error)
}

type Message

type Message interface {
	Cmd() MsgType
}

func UnmarshalMessage

func UnmarshalMessage(name MsgType, data []byte) (Message, error)

type ModFeatures

type ModFeatures map[Feature]bool

func (ModFeatures) Clone

func (f ModFeatures) Clone() ModFeatures

func (ModFeatures) Intersect

func (f ModFeatures) Intersect(fp ModFeatures) ModFeatures

func (ModFeatures) IsSet

func (f ModFeatures) IsSet(s Feature) bool

func (ModFeatures) Join

func (f ModFeatures) Join() string

func (ModFeatures) MarshalAdc

func (f ModFeatures) MarshalAdc() ([]byte, error)

func (ModFeatures) SetFrom

func (f ModFeatures) SetFrom(fp ModFeatures) ModFeatures

func (*ModFeatures) UnmarshalAdc

func (f *ModFeatures) UnmarshalAdc(s []byte) error

type MsgType

type MsgType [3]byte

func (MsgType) String

func (s MsgType) String() string

type NoArgs added in v0.8.15

type NoArgs struct{}

func (NoArgs) MarshalAdc added in v0.8.15

func (m NoArgs) MarshalAdc() ([]byte, error)

func (*NoArgs) UnmarshalAdc added in v0.8.15

func (m *NoArgs) UnmarshalAdc(data []byte) error

type PID

type PID = CID

type PM

type PM struct {
	Text string `adc:"#"`
	Src  SID    `adc:"PM"`
}

type Packet

type Packet interface {
	Kind() byte
	Message() RawMessage
	SetMessage(m RawMessage)
	Decode() (Message, error)
	UnmarshalPacket(name MsgType, data []byte) error
	MarshalPacket() ([]byte, error)
}

func DecodePacket

func DecodePacket(p []byte) (Packet, error)

type Password

type Password struct {
	Hash tiger.Hash `adc:"#"`
}

func (Password) Cmd

func (Password) Cmd() MsgType

type Path

type Path []string

func (Path) MarshalAdc

func (p Path) MarshalAdc() ([]byte, error)

func (*Path) UnmarshalAdc

func (p *Path) UnmarshalAdc(data []byte) error

type PeerPacket

type PeerPacket interface {
	Packet
	Source() SID
}

type PingConfig added in v0.8.12

type PingConfig struct {
	Name       string
	ShareSize  uint64
	ShareFiles int
	Slots      int
	Hubs       int
}

type PingHubInfo

type PingHubInfo struct {
	HubInfo
	Ext   []string
	Users []User
}

func Ping

func Ping(ctx context.Context, addr string, conf PingConfig) (*PingHubInfo, error)

type RawMessage

type RawMessage struct {
	Type MsgType
	Data []byte
}

func (RawMessage) Cmd

func (m RawMessage) Cmd() MsgType

func (RawMessage) MarshalAdc

func (m RawMessage) MarshalAdc() ([]byte, error)

func (*RawMessage) UnmarshalAdc

func (m *RawMessage) UnmarshalAdc(data []byte) error

type RevConnectRequest

type RevConnectRequest struct {
	Proto string `adc:"#"`
	Token string `adc:"#"`
}

func (RevConnectRequest) Cmd

func (RevConnectRequest) Cmd() MsgType

type Route

type Route interface {
	WriteMessage(msg Message) error
	Flush() error
}

type SID

type SID = types.SID

type SIDAssign

type SIDAssign struct {
	SID SID
}

func (SIDAssign) Cmd

func (SIDAssign) Cmd() MsgType

func (SIDAssign) MarshalAdc

func (m SIDAssign) MarshalAdc() ([]byte, error)

func (*SIDAssign) UnmarshalAdc

func (m *SIDAssign) UnmarshalAdc(data []byte) error

type SearchRequest

type SearchRequest struct {
	Token string   `adc:"TO"`
	And   []string `adc:"AN"`
	Not   []string `adc:"NO"`
	Ext   []string `adc:"EX"`

	Le int64 `adc:"LE"`
	Ge int64 `adc:"GE"`
	Eq int64 `adc:"EQ"`

	Type FileType `adc:"TY"`

	// TIGR ext
	TTH *TTH `adc:"TR"`

	// SEGA ext
	Group ExtGroup `adc:"GR"`
	NoExt []string `adc:"RX"`
}

func (SearchRequest) Cmd

func (SearchRequest) Cmd() MsgType

type SearchResult

type SearchResult struct {
	Token string `adc:"TO"`
	Path  string `adc:"FN"`
	Size  int64  `adc:"SI"`
	Slots int    `adc:"SL"`

	// TIGR ext
	TTH *TTH `adc:"TR"`
}

func (SearchResult) Cmd

func (SearchResult) Cmd() MsgType

type Severity

type Severity int

type Status

type Status struct {
	Sev  Severity
	Code int
	Msg  string
}

func (Status) Cmd

func (Status) Cmd() MsgType

func (Status) Err

func (st Status) Err() error

func (Status) MarshalAdc

func (st Status) MarshalAdc() ([]byte, error)

func (Status) Ok

func (st Status) Ok() bool

func (Status) Recoverable

func (st Status) Recoverable() bool

func (*Status) UnmarshalAdc

func (st *Status) UnmarshalAdc(s []byte) error

type String

type String string

func (String) MarshalAdc

func (f String) MarshalAdc() ([]byte, error)

func (*String) UnmarshalAdc

func (f *String) UnmarshalAdc(s []byte) error

type Supported

type Supported struct {
	Features ModFeatures
}

func (Supported) Cmd

func (Supported) Cmd() MsgType

func (Supported) MarshalAdc

func (m Supported) MarshalAdc() ([]byte, error)

func (*Supported) UnmarshalAdc

func (m *Supported) UnmarshalAdc(data []byte) error

type TTH

type TTH = tiger.Hash

TTH is a Tiger Tree Hash value.

type Tag

type Tag [2]byte

func (Tag) String

func (f Tag) String() string

type TargetPacket

type TargetPacket interface {
	PeerPacket
	Target() SID
}

type UDPPacket

type UDPPacket struct {
	BasePacket
	ID CID
}

func (*UDPPacket) Kind added in v0.16.4

func (*UDPPacket) Kind() byte

func (*UDPPacket) MarshalPacket

func (p *UDPPacket) MarshalPacket() ([]byte, error)

func (*UDPPacket) UnmarshalPacket

func (p *UDPPacket) UnmarshalPacket(name MsgType, data []byte) error

type Unmarshaler

type Unmarshaler interface {
	UnmarshalAdc(data []byte) error
}

type User

type User struct {
	Id   CID    `adc:"ID"`
	Pid  *PID   `adc:"PD"` // sent only to hub
	Name string `adc:"NI,req"`

	Ip4  string `adc:"I4"`
	Ip6  string `adc:"I6"`
	Udp4 int    `adc:"U4"`
	Udp6 int    `adc:"U6"`

	ShareSize  int64 `adc:"SS,req"`
	ShareFiles int   `adc:"SF,req"`

	Version     string `adc:"VE,req"`
	Application string `adc:"AP"`

	MaxUpload   string `adc:"US"`
	MaxDownload string `adc:"DS"`

	Slots         int `adc:"SL,req"`
	SlotsFree     int `adc:"FS,req"`
	AutoSlotLimit int `adc:"AS"`

	Email string `adc:"EM"`
	Desc  string `adc:"DE"`

	HubsNormal     int `adc:"HN,req"`
	HubsRegistered int `adc:"HR,req"`
	HubsOperator   int `adc:"HO,req"`

	Token string `adc:"TO"` // C-C only

	Type UserType `adc:"CT"`
	Away AwayType `adc:"AW"`
	Ref  string   `adc:"RF"`

	Features ExtFeatures `adc:"SU,req"`

	KP string `adc:"KP"`

	Address string `adc:"EA"`
}

func (User) Cmd

func (User) Cmd() MsgType

func (*User) Normalize

func (u *User) Normalize()

type UserCommand

type UserCommand struct {
	Path        Path     `adc:"#"`
	Command     string   `adc:"TT"`
	Category    Category `adc:"CT"`
	Remove      int      `adc:"RM"`
	Constrained int      `adc:"CO"`
	Separator   int      `adc:"SP"`
}

func (UserCommand) Cmd

func (UserCommand) Cmd() MsgType

type UserMod

type UserMod map[Tag]string

func (UserMod) Cmd

func (UserMod) Cmd() MsgType

func (UserMod) MarshalAdc

func (m UserMod) MarshalAdc() ([]byte, error)

func (*UserMod) UnmarshalAdc

func (m *UserMod) UnmarshalAdc(data []byte) error

type UserType

type UserType int
const (
	UserTypeNone       UserType = 0x00
	UserTypeBot        UserType = 0x01
	UserTypeRegistered UserType = 0x02
	UserTypeOperator   UserType = 0x04
	UserTypeSuperUser  UserType = 0x08
	UserTypeHubOwner   UserType = 0x10
	UserTypeHub        UserType = 0x20
	UserTypeHidden     UserType = 0x40
)

func (UserType) Is

func (t UserType) Is(st UserType) bool

type ZOff added in v0.8.15

type ZOff struct {
	NoArgs
}

func (ZOff) Cmd added in v0.8.15

func (ZOff) Cmd() MsgType

type ZOn added in v0.8.15

type ZOn struct {
	NoArgs
}

func (ZOn) Cmd added in v0.8.15

func (ZOn) Cmd() MsgType

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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