Documentation
¶
Overview ¶
Package dctk implements the client part of the Direct Connect peer-to-peer system (ADC and NMDC protocols) in the Go programming language. It allows the creation of clients that can interact with hubs and other clients, and can be used as backend to user interfaces or automatic bots.
Examples are available at https://github.com/aler9/dctk/tree/master/examples
Index ¶
- type Client
- func (c *Client) Close() error
- func (c *Client) Conf() ClientConf
- func (c *Client) DownloadCount() int
- func (c *Client) DownloadFLDirectory(peer *Peer, dir *FileListDirectory, savePath string) error
- func (c *Client) DownloadFLFile(peer *Peer, file *FileListFile, savePath string) (*Download, error)
- func (c *Client) DownloadFile(conf DownloadConf) (*Download, error)
- func (c *Client) DownloadFileList(peer *Peer, savePath string) (*Download, error)
- func (c *Client) HubConnect()
- func (c *Client) MessagePrivate(dest *Peer, content string)
- func (c *Client) MessagePublic(content string)
- func (c *Client) Peers() map[string]*Peer
- func (c *Client) Run()
- func (c *Client) Safe(cb func())
- func (c *Client) Search(conf SearchConf) error
- func (c *Client) ShareAdd(alias string, dpath string)
- func (c *Client) ShareDel(alias string)
- type ClientConf
- type Download
- type DownloadConf
- type EncryptionMode
- type FileList
- type FileListDirectory
- type FileListFile
- type HubField
- type Peer
- type SearchConf
- type SearchResult
- type SearchType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { // OnInitialized is called just after client initialization, before connecting to the hub OnInitialized func() OnShareIndexed func() // OnHubConnected is called when the connection between client and hub has been established OnHubConnected func() // OnHubError is called when a critical error happens OnHubError func(err error) // OnHubInfo is called when an information about the hub is received OnHubInfo func(field HubField, value string) // OnHubTLS is called when a TLS connection with a hub is established OnHubTLS func(st tls.ConnectionState) // OnHubProto is called when a protocol for the hub is selected OnHubProto func(proto string) // OnPeerConnected is called when a peer connects to the hub OnPeerConnected func(p *Peer) // OnPeerUpdated is called when a peer has just updated its informations OnPeerUpdated func(p *Peer) // OnPeerDisconnected is called when a peer disconnects from the hub OnPeerDisconnected func(p *Peer) // OnMessagePublic is called when someone writes in the hub public chat. // When using ADC, it is also called when the hub sends a message. OnMessagePublic func(p *Peer, content string) // OnMessagePrivate is called when a private message has been received OnMessagePrivate func(p *Peer, content string) // OnSearchResult is called when a search result has been received OnSearchResult func(r *SearchResult) // OnDownloadSuccessful is called when a given download has finished OnDownloadSuccessful func(d *Download) // OnDownloadError is called when a given download has failed OnDownloadError func(d *Download) // contains filtered or unexported fields }
Client represents a local client.
func NewClient ¶
func NewClient(conf ClientConf) (*Client, error)
NewClient is used to initialize a client. See ClientConf for the available options.
func (*Client) Conf ¶
func (c *Client) Conf() ClientConf
Conf returns the configuration passed during client initialization.
func (*Client) DownloadCount ¶
DownloadCount returns the number of remaining downloads, queued or active.
func (*Client) DownloadFLDirectory ¶
func (c *Client) DownloadFLDirectory(peer *Peer, dir *FileListDirectory, savePath string) error
DownloadFLDirectory starts downloading recursively all the files inside a file list directory.
func (*Client) DownloadFLFile ¶
DownloadFLFile starts downloading a file given a file list entry.
func (*Client) DownloadFile ¶
func (c *Client) DownloadFile(conf DownloadConf) (*Download, error)
DownloadFile starts downloading a file by its Tiger Tree Hash (TTH). See DownloadConf for the options.
func (*Client) DownloadFileList ¶
DownloadFileList starts downloading the file list of a given peer.
func (*Client) HubConnect ¶
func (c *Client) HubConnect()
HubConnect starts the connection to the hub. It must be called only when HubManualConnect is true.
func (*Client) MessagePrivate ¶
MessagePrivate sends a private message to a specific peer connected to the hub.
func (*Client) MessagePublic ¶
MessagePublic publishes a message in the hub public chat.
func (*Client) Run ¶
func (c *Client) Run()
Run starts the client and waits until the client has been terminated.
func (*Client) Safe ¶
func (c *Client) Safe(cb func())
Safe is used to safely execute code outside the client context. It must be used when interacting with the client outside the callbacks (i.e. inside a parallel goroutine).
func (*Client) Search ¶
func (c *Client) Search(conf SearchConf) error
Search starts a file search asynchronously. See SearchConf for the available options.
func (*Client) ShareAdd ¶
ShareAdd adds a given directory (dpath) to the client share, with the given alias, and starts indexing its subdirectories and files. if a directory with the same alias was added previously, it is replaced with the new one. OnShareIndexed is called when the indexing is finished.
type ClientConf ¶
type ClientConf struct { // verbosity of the library LogLevel log.Level // turns on passive mode: it is not necessary anymore to open TCPPort, UDPPort // and TLSPort but functionalities are limited IsPassive bool // (optional) an explicit ip, instead of the one obtained automatically IP string // these are the 3 ports needed for active mode. They must be accessible from the // internet, so any router/firewall in between must be configured TCPPort uint UDPPort uint TLSPort uint // the maximum number of file to download in parallel. When this number is // exceeded, the other downloads are queued and started when a slot becomes available DownloadMaxParallel uint // the maximum number of file to upload in parallel UploadMaxParallel uint // set the policy regarding encryption with other peers. See EncryptionMode for options PeerEncryptionMode EncryptionMode // The hub url in the format protocol://address:port // supported protocols are adc, adcs, nmdc and nmdcs HubURL string // how many times attempting a connection with hub before giving up HubConnTries uint // if turned on, connection to hub is not automatic and HubConnect() must be // called manually HubManualConnect bool // the nickname to use in the hub and with other peers Nick string // the password associated with the nick, if requested by the hub Password string // the private ID of the user (ADC only) PID atypes.PID // an email, optional Email string // a description, optional Description string // the maximum upload speed in bytes/sec. It is not really applied, but is sent to the hub UploadMaxSpeed uint // these are used to identify the software. By default they mimic DC++ ClientString string ClientVersion string PkValue string ListGenerator string // options useful only for debugging purposes HubDisableCompression bool PeerDisableCompression bool HubDisableKeepAlive bool }
ClientConf allows to configure a client.
type Download ¶
type Download struct {
// contains filtered or unexported fields
}
Download represents an in-progress file download.
func (*Download) Close ¶
func (d *Download) Close()
Close stops the download. OnDownloadError and OnDownloadSuccessful are not called.
func (*Download) Conf ¶
func (d *Download) Conf() DownloadConf
Conf returns the configuration passed at download initialization.
type DownloadConf ¶
type DownloadConf struct { // the peer from which downloading Peer *Peer // the TTH of the file to download TTH tiger.Hash // the starting point of the file part to download, in bytes Start uint64 // the length of the file part. Leave zero to download the entire file Length int64 // if filled, the file is saved on the desired path on disk, otherwise it is kept on RAM SavePath string // after download, do not attempt to validate the file through its TTH SkipValidation bool // contains filtered or unexported fields }
DownloadConf allows to configure a download.
type EncryptionMode ¶
type EncryptionMode int
EncryptionMode contains the options regarding encryption.
const ( // PreferEncryption uses encryption when the two peers both support it PreferEncryption EncryptionMode = iota // DisableEncryption disables competely encryption DisableEncryption // ForceEncryption forces encryption and block interaction with peers that // do not support encrypton ForceEncryption )
type FileList ¶
type FileList struct { XMLName xml.Name `xml:"FileListing"` Version string `xml:"Version,attr"` CID string `xml:"CID,attr"` Base string `xml:"Base,attr"` Generator string `xml:"Generator,attr"` Dirs []*FileListDirectory `xml:"Directory"` }
FileList is a user file list, containing directories and files.
func FileListParse ¶
FileListParse parses a given user file list in XML format into a FileList struct.
func (*FileList) Export ¶
Export transform the FileList struct into a user file list in the XML format.
func (*FileList) GetDirectory ¶
func (fl *FileList) GetDirectory(dpath string) (*FileListDirectory, error)
GetDirectory returns the directory in the file list corresponding to the given path.
type FileListDirectory ¶
type FileListDirectory struct { Name string `xml:"Name,attr"` Files []*FileListFile `xml:"File"` Dirs []*FileListDirectory `xml:"Directory"` }
FileListDirectory is part of a user file list and represents a shared drectory.
type FileListFile ¶
type FileListFile struct { Name string `xml:"Name,attr"` Size uint64 `xml:"Size,attr"` TTH tiger.Hash `xml:"TTH,attr"` }
FileListFile is part of a user file list and represents a shared file.
type Peer ¶
type Peer struct { // peer nickname Nick string // peer description (if provided) Description string // peer email (if provided) Email string // whether peer is a bot IsBot bool // whether peer is a operator IsOperator bool // client used by peer (in NMDC this could be hidden) Client string // version of client (in NMDC this could be hidden) Version string ShareSize uint64 // whether peer is in passive mode (in NMDC this could be hidden) IsPassive bool // peer ip (if provided by both peer and hub) IP string // contains filtered or unexported fields }
Peer represents a remote client connected to a Hub.
type SearchConf ¶
type SearchConf struct { // the search type, defaults to SearchAny. See SearchType for all the available options Type SearchType // the minimum size of the searched file (if type is SearchAny or SearchTTH) MinSize uint64 // the maximum size of the searched file (if type is SearchAny or SearchTTH) MaxSize uint64 // part of a file name (if type is SearchAny), part of a directory name // (if type is SearchAny or SearchDirectory) Query string // file TTH (if type is SearchTTH) TTH tiger.Hash }
SearchConf allows to configure a search request.
type SearchResult ¶
type SearchResult struct { // whether the search result was received in passive or active mode IsActive bool // the peer sending the result Peer *Peer // path of a file or directory matching a search request Path string // whether the result is a directory IsDir bool // size (file only in NMDC, both files and directories in ADC) Size uint64 // TTH (file only) TTH *tiger.Hash // the available upload slots of the peer SlotAvail uint }
SearchResult contains a single result received after a search request.
type SearchType ¶
type SearchType int
SearchType contains the search type.
const ( // SearchAny searches for a file or directory by name SearchAny SearchType = iota // SearchDirectory searches for a directory by name SearchDirectory // SearchTTH searches for a file by TTH SearchTTH )
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
cmd
|
|
dc-download
dc-download command.
|
dc-download command. |
dc-search
dc-search command.
|
dc-search command. |
dc-share
dc-share command.
|
dc-share command. |
dc-tth
dc-tth command.
|
dc-tth command. |
examples
|
|
pkg
|
|
log
Package log provides a logger.
|
Package log provides a logger. |
protoadc
Package protoadc provides an ADC connection implementation.
|
Package protoadc provides an ADC connection implementation. |
protocommon
Package protocommon contains shared elements between ADC and NMDC connections.
|
Package protocommon contains shared elements between ADC and NMDC connections. |
protonmdc
Package protonmdc provides a NMDC connection implementation.
|
Package protonmdc provides a NMDC connection implementation. |
tiger
Package tiger provides the Tiger hash.
|
Package tiger provides the Tiger hash. |
test-manual
|
|
client
manual client.
|
manual client. |