Documentation ¶
Index ¶
- Constants
- Variables
- func Marshal(o interface{}) ([]byte, error)
- func MustMarshal(o interface{}) []byte
- func RegisterMessage(m Message)
- func Unmarshal(s []byte, o interface{}) error
- type AddFeatures
- type AwayType
- type BasePacket
- type BoolInt
- type BroadcastPacket
- type CID
- type Category
- type ChatMessage
- type ClientPacket
- type Conn
- func (c *Conn) Broadcast(from SID) Route
- func (c *Conn) Close() error
- func (c *Conn) Direct(from, to SID) Route
- func (c *Conn) Flush() error
- func (c *Conn) KeepAlive(interval time.Duration)
- func (c *Conn) LocalAddr() net.Addr
- func (c *Conn) ReadBinary(n int64) io.ReadCloser
- func (c *Conn) ReadClientMsg(deadline time.Time) (Message, error)
- func (c *Conn) ReadInfoMsg(deadline time.Time) (Message, error)
- func (c *Conn) ReadPacket(deadline time.Time) (Packet, error)
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) WriteBroadcast(id SID, msg Message) error
- func (c *Conn) WriteClientMsg(msg Message) error
- func (c *Conn) WriteDirect(id, targ SID, msg Message) error
- func (c *Conn) WriteEcho(id, targ SID, msg Message) error
- func (c *Conn) WriteHubMsg(msg Message) error
- func (c *Conn) WriteInfoMsg(msg Message) error
- func (c *Conn) WritePacket(p Packet) error
- type ConnectRequest
- type DirectPacket
- type Disconnect
- type EchoPacket
- type Error
- type ExtFeatures
- type ExtGroup
- type Feature
- type FeaturePacket
- type FileType
- type GetInfoRequest
- type GetPassword
- type GetRequest
- type GetResponse
- type HubInfo
- type HubPacket
- type InfoPacket
- type Marshaler
- type Message
- type ModFeatures
- func (f ModFeatures) Clone() ModFeatures
- func (f ModFeatures) Intersect(fp ModFeatures) ModFeatures
- func (f ModFeatures) IsSet(s Feature) bool
- func (f ModFeatures) Join() string
- func (f ModFeatures) MarshalAdc() ([]byte, error)
- func (f ModFeatures) SetFrom(fp ModFeatures) ModFeatures
- func (f *ModFeatures) UnmarshalAdc(s []byte) error
- type MsgType
- type PID
- type PM
- type Packet
- type Password
- type Path
- type PeerPacket
- type PingConfig
- type PingHubInfo
- type RawMessage
- type RevConnectRequest
- type Route
- type SID
- type SIDAssign
- type SearchRequest
- type SearchResult
- type Severity
- type Status
- type String
- type Supported
- type TTH
- type Tag
- type TargetPacket
- type UDPPacket
- type Unmarshaler
- type User
- type UserCommand
- type UserMod
- type UserType
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 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 MustMarshal ¶
func MustMarshal(o interface{}) []byte
func RegisterMessage ¶
func RegisterMessage(m Message)
Types ¶
type AddFeatures ¶
type AddFeatures []string
func (AddFeatures) MarshalAdc ¶
func (f AddFeatures) MarshalAdc() (string, error)
type BasePacket ¶
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 BroadcastPacket ¶
type BroadcastPacket struct { BasePacket ID SID }
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 ChatMessage ¶
func (ChatMessage) Cmd ¶
func (ChatMessage) Cmd() MsgType
type ClientPacket ¶
type ClientPacket struct {
BasePacket
}
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 DialContext ¶
DialContext connects to a specified address.
func (*Conn) ReadBinary ¶
func (c *Conn) ReadBinary(n int64) io.ReadCloser
func (c *Conn) HubHandshake(f ModFeatures, sid SID, info HubInfo) (*User, error) { const initialWait = time.Second * 5 // Read supported features from the client cmd, err := c.ReadPacket(initialWait) if err != nil { return nil, err } else if cmd.Kind() != kindHub || cmd.GetName() != CmdSupport { return nil, fmt.Errorf("expected SUP command, got: %v, %v", cmd.Kind(), cmd.GetName()) } f = f.SetFrom(supExtensionsHub2Cli) var fea = make(ModFeatures) if err = Unmarshal(string(cmd.Data()), &fea); err != nil { return nil, err } c.fea = f.Intersect(fea) if Debug { log.Printf("features: %v, mutual: %v\n", fea, c.fea) } if !c.fea.IsSet(FeaTIGR) { return nil, fmt.Errorf("client has no support for TIGR") } else if !c.fea.IsSet(FeaBASE) { return nil, fmt.Errorf("client has no support for BASE") } //c.zlibGet = c.fea[extZLIG] // Send ours supported features c.WritePacket(NewInfoCmd(CmdSupport, f)) // Assign SID to the client c.WritePacket(NewInfoCmd(CmdSession, sid)) // Send hub info c.WritePacket(NewInfoCmd(CmdInfo, info)) // Write OK status c.WritePacket(NewInfoCmd(CmdStatus, Status{Msg: "Powered by Gophers"})) if err := c.Flush(); err != nil { return nil, err } cmd, err = c.ReadPacket(initialWait) if err != nil { return nil, err } ucmd, ok := cmd.(BroadcastPacket) if !ok || ucmd.Name != CmdInfo { return nil, fmt.Errorf("expected INF command, got: %v, %v", cmd.Kind(), cmd.GetName()) } var user User if err = Unmarshal(string(ucmd.Data), &user); err != nil { return nil, fmt.Errorf("failed to unmarshal user info: %v", err) } return &user, nil }
func (c *Conn) ClientHandshake(toHub bool, f ModFeatures) error { // TODO: ctx
if len(f) == 0 { if toHub { f = supExtensionsCli2Hub.Clone() } else { f = supExtensionsCli2Cli.Clone() } } if _, ok := f[extZLIG]; !ok { f[extZLIG] = UseZLibGet } // Send supported features and initiate state machine if toHub { c.WritePacket(NewHubCmd(CmdSupport, f)) } else { c.WritePacket(NewClientCmd(CmdSupport, f)) } if err := c.Flush(); err != nil { return err } const protocolWait = time.Second * 5 for { cmd, err := c.ReadPacket(protocolWait) if err != nil { return err } else if (toHub && cmd.Kind() != kindInfo) || (!toHub && cmd.Kind() != kindClient) { return fmt.Errorf("unexpected command kind in Protocol, got: %v", cmd) } switch cmd.GetName() { case CmdStatus: fmt.Println("got status in Protocol:", cmd) case CmdSupport: // Expect to get supported extensions back var fea = make(ModFeatures) Unmarshal(string(cmd.Data()), &fea) c.fea = f.Intersect(fea) fmt.Printf("features: %v, mutual: %v\n", fea, c.fea) if !c.fea.IsSet(FeaTIGR) { return fmt.Errorf("peer has no support for TIGR") } else if !c.fea.IsSet(FeaBASE) && !c.fea.IsSet("BAS0") { return fmt.Errorf("peer has no support for BASE") } c.zlibGet = c.fea[extZLIG] if !toHub { return nil } case CmdSession: // Hub must send a SID for us if !toHub { return fmt.Errorf("unexpected session in C-C connection: %v", cmd) } else if len(cmd.Data()) != 4 { return fmt.Errorf("wrong SID format: '%s'", cmd.Data()) } if err := c.sid.UnmarshalAdc(string(cmd.Data())); err != nil { return err } fmt.Println("SID:", c.sid) return nil default: return fmt.Errorf("unexpected command in Protocol: %v", cmd) } } }
ReadBinary acquires an exclusive reader lock on the connection and switches it to binary mode. Reader will be limited to exactly n bytes. Unread content will be discarded on close.
func (*Conn) ReadPacket ¶
ReadPacket reads and decodes a single ADC command.
func (*Conn) RemoteAddr ¶
func (*Conn) WriteClientMsg ¶
func (*Conn) WriteHubMsg ¶
func (*Conn) WriteInfoMsg ¶
func (*Conn) WritePacket ¶
type ConnectRequest ¶
func (ConnectRequest) Cmd ¶
func (ConnectRequest) Cmd() MsgType
type DirectPacket ¶
type DirectPacket struct { BasePacket ID SID Targ SID }
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
}
func (Disconnect) Cmd ¶
func (Disconnect) Cmd() MsgType
func (Disconnect) MarshalAdc ¶
func (m Disconnect) MarshalAdc() ([]byte, error)
func (*Disconnect) UnmarshalAdc ¶
func (m *Disconnect) UnmarshalAdc(data []byte) error
type EchoPacket ¶
type EchoPacket DirectPacket
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 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 FeaturePacket ¶
type FeaturePacket struct { BasePacket ID SID Features map[Feature]bool }
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 GetInfoRequest ¶
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 Files int `adc:"SF"` // Total files shared 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) }
type InfoPacket ¶
type InfoPacket struct {
BasePacket
}
func (*InfoPacket) MarshalPacket ¶
func (p *InfoPacket) MarshalPacket() ([]byte, error)
func (*InfoPacket) UnmarshalPacket ¶
func (p *InfoPacket) UnmarshalPacket(name MsgType, data []byte) error
type ModFeatures ¶
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 Packet ¶
type Packet interface { Message() RawMessage SetMessage(m RawMessage) Decode() (Message, error) UnmarshalPacket(name MsgType, data []byte) error MarshalPacket() ([]byte, error) // contains filtered or unexported methods }
func DecodePacket ¶
type PeerPacket ¶
type PingConfig ¶ added in v0.8.12
type PingHubInfo ¶
func Ping ¶
func Ping(ctx context.Context, addr string, conf PingConfig) (*PingHubInfo, error)
type RawMessage ¶
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 ¶
func (RevConnectRequest) Cmd ¶
func (RevConnectRequest) Cmd() MsgType
type SIDAssign ¶
type SIDAssign struct {
SID SID
}
func (SIDAssign) MarshalAdc ¶
func (*SIDAssign) UnmarshalAdc ¶
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 Supported ¶
type Supported struct {
Features ModFeatures
}
func (Supported) MarshalAdc ¶
func (*Supported) UnmarshalAdc ¶
type TargetPacket ¶
type TargetPacket interface { PeerPacket Target() SID }
type Unmarshaler ¶
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"` 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"` }
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
Source Files ¶
Click to show internal directories.
Click to hide internal directories.