Documentation
¶
Overview ¶
Package peer messages are sent to peers over a P connection (TCP). Only a single active connection to a peer is allowed.
Index ¶
- Constants
- Variables
- func MessageRead[C CodeInit | Code](c C, connection net.Conn) (io.Reader, int, C, error)
- func MessageWrite(connection net.Conn, message []byte) (int, error)
- func Reason(reason string) error
- type Attribute
- type Code
- type CodeInit
- type Directory
- type File
- type FileAttributeType
- type FileSearchResponse
- type Folder
- type FolderContentsRequest
- type FolderContentsResponse
- type PeerInit
- type PierceFirewall
- type PlaceInQueueRequest
- type PlaceInQueueResponse
- type QueueUpload
- type SharedFileListRequest
- type SharedFileListResponse
- type TransferDirection
- type TransferRequest
- type TransferResponse
- type UploadDenied
- type UploadFailed
- type UploadPermission
- type UserInfoRequest
- type UserInfoResponse
Constants ¶
const ConnectionType soul.ConnectionType = "P"
ConnectionType represents the type of peer 'P' connection.
Variables ¶
var ErrBanned = errors.New("Banned")
ErrBanned is returned when the transfer is not allowed because the peer is banned.
var ErrCancelled = errors.New("Cancelled")
ErrCancelled is returned when the transfer is not allowed because it was cancelled.
var ErrComplete = errors.New("Complete")
ErrComplete is returned when the transfer is complete.
var ErrEmptyDirectory = errors.New("directory is empty")
ErrEmptyDirectory is returned when the directory is empty.
var ErrEmptyDirectoryName = errors.New("directory name is empty")
ErrEmptyDirectoryName is returned when the directory name is empty.
var ErrEmptyFileExtension = errors.New("file extension is empty")
ErrEmptyFileExtension is returned when the file extension is empty.
var ErrEmptyFileName = errors.New("file name is empty")
ErrEmptyFileName is returned when the file name is empty.
ErrFileNotShared is returned when the transfer is not allowed because the file is not shared.
var ErrFileReadError = errors.New("File read error.")
ErrFileReadError is returned when the transfer is not allowed because of a file read error.
var ErrNoDirectories = errors.New("no directories")
ErrNoDirectories is returned when there are no directories.
var ErrNotAllowedWithNoReason = errors.New("rejection reason is required when transfer is not allowed")
ErrNotAllowedWithNoReason is returned when a TransferResponse is not allowed and no reason is provided.
var ErrPendingShutdown = errors.New("Pending shutdown.")
ErrPendingShutdown is returned when the transfer is not allowed because of a pending shutdown.
var ErrQueued = errors.New("Queued")
ErrQueued is returned when the transfer is queued.
var ErrSizeZero = errors.New("file size is zero")
ErrSizeZero is returned when the file size is zero.
var ErrTooManyFiles = errors.New("Too many files")
ErrTooManyFiles is returned when the transfer is not allowed because there are too many files.
var ErrTooManyMegabytes = errors.New("Too many megabytes")
ErrTooManyMegabytes is returned when the transfer is not allowed because there are too many megabytes.
Functions ¶
func MessageRead ¶ added in v1.1.0
func MessageWrite ¶ added in v1.1.0
Types ¶
type Attribute ¶
type Attribute struct {
Code FileAttributeType
Value uint32
}
Attribute is a type of file attribute.
type Code ¶ added in v1.0.0
type Code int
Code Peer messages are sent to peers over a P connection (TCP). Only a single active connection to a peer is allowed.
const CodeFileSearchResponse Code = 9
const CodeFolderContentsRequest Code = 36
const CodeFolderContentsResponse Code = 37
const CodePlaceInQueueRequest Code = 51
const CodePlaceInQueueResponse Code = 44
const CodeQueueUpload Code = 43
const CodeTransferRequest Code = 40
const CodeTransferResponse Code = 41
const CodeUploadDenied Code = 50
const CodeUploadFailed Code = 46
const CodeUserInfoRequest Code = 15
const CodeUserInfoResponse Code = 16
type CodeInit ¶ added in v1.0.0
type CodeInit int
CodeInit Peer init messages are used to initiate a P, F or D connection (TCP) to a peer.
const CodePeerInit CodeInit = 1
const CodePierceFirewall CodeInit = 0
type FileAttributeType ¶ added in v0.0.2
type FileAttributeType int
FileAttributeType represents the type of file attribute.
const ( // Bitrate (kbps). Bitrate FileAttributeType = iota // Duration (seconds). Duration // VBR (0 or 1). VBR // SampleRate (Hz). SampleRate // BitDepth (bits). BitDepth )
func (FileAttributeType) String ¶ added in v1.0.0
func (i FileAttributeType) String() string
type FileSearchResponse ¶ added in v1.0.0
type FileSearchResponse struct {
Username string
Token soul.Token
Results []File
FreeSlot bool
AverageSpeed int
Queue int // Queue is the length of the queued transfers.
PrivateResults []File
}
FileSearchResponse code 9 peer sends this message when it has a file search match. The token is taken from original FileSearch, UserSearch or RoomSearch server message.
func (*FileSearchResponse) Deserialize ¶ added in v1.0.0
func (f *FileSearchResponse) Deserialize(reader io.Reader) error
func (FileSearchResponse) Serialize ¶ added in v1.0.0
func (f FileSearchResponse) Serialize(fs FileSearchResponse) ([]byte, error)
Serialize accepts a FileSearchResponse and returns a message packed as a byte slice.
type FolderContentsRequest ¶ added in v1.0.0
FolderContentsRequest code 36 we ask the peer to send us the contents of a single folder.
func (*FolderContentsRequest) Deserialize ¶ added in v1.0.0
func (f *FolderContentsRequest) Deserialize(reader io.Reader) error
type FolderContentsResponse ¶ added in v1.0.0
FolderContentsResponse code 37 peer responds with the contents of a particular folder (with all subfolders) after we’ve sent a FolderContentsRequest.
func (*FolderContentsResponse) Deserialize ¶ added in v1.0.0
func (f *FolderContentsResponse) Deserialize(reader io.Reader) error
type PeerInit ¶ added in v0.0.2
type PeerInit struct {
// RemoteUsername is the username of the peer that wants to connect to us.
RemoteUsername string
ConnectionType soul.ConnectionType
}
PeerInit code 1 message is sent to initiate a direct connection to another peer.
func (*PeerInit) Deserialize ¶ added in v0.0.2
type PierceFirewall ¶ added in v0.0.2
PierceFirewall code 0 message is sent in response to an indirect connection request from another user. If the message goes through to the user, the connection is ready. The token is taken from the ConnectToPeer server message.
func (*PierceFirewall) Deserialize ¶ added in v0.0.2
func (p *PierceFirewall) Deserialize(reader io.Reader) error
type PlaceInQueueRequest ¶ added in v1.0.0
type PlaceInQueueRequest struct {
Filename string
}
PlaceInQueueRequest code 51 message is sent when asking for the upload queue placement of a file.
func (*PlaceInQueueRequest) Deserialize ¶ added in v1.0.0
func (p *PlaceInQueueRequest) Deserialize(reader io.Reader) error
type PlaceInQueueResponse ¶ added in v1.0.0
PlaceInQueueResponse code 44 peer replies with the upload queue placement of the requested file.
func (*PlaceInQueueResponse) Deserialize ¶ added in v1.0.0
func (p *PlaceInQueueResponse) Deserialize(reader io.Reader) error
type QueueUpload ¶ added in v1.0.0
type QueueUpload struct {
Filename string
}
QueueUpload code 43 this message is used to tell a peer that an upload should be queued on their end. Once the recipient is ready to transfer the requested file, they will send a TransferRequest to us.
func (*QueueUpload) Deserialize ¶ added in v1.0.0
func (q *QueueUpload) Deserialize(reader io.Reader) error
type SharedFileListRequest ¶
type SharedFileListRequest struct{}
func (*SharedFileListRequest) Deserialize ¶
func (s *SharedFileListRequest) Deserialize(reader io.Reader) error
func (SharedFileListRequest) Serialize ¶
func (SharedFileListRequest) Serialize() ([]byte, error)
type SharedFileListResponse ¶
type SharedFileListResponse struct {
}
SharedFileListResponse code 5 peer responds with a list of shared files after we’ve sent a SharedFileListRequest.
func (*SharedFileListResponse) Deserialize ¶
func (s *SharedFileListResponse) Deserialize(reader io.Reader) error
Deserialize accepts a reader and deserializes the message into the SharedFileListResponse struct.
func (SharedFileListResponse) Serialize ¶
func (s SharedFileListResponse) Serialize(directories, privateDirectories []Directory) ([]byte, error)
Serialize accepts directories and privateDirectories and returns a message packed as a byte slice. It uses custom errors for the following cases: - ErrNoDirectories is returned when there are no directories. - ErrEmptyDirectoryName is returned when the directory name is empty. - ErrEmptyDirectory is returned when the directory is empty. - ErrEmptyFileName is returned when the file name is empty. - ErrSizeZero is returned when the file size is zero. - ErrEmptyFileExtension is returned when the file extension is empty. You can use them in your code to check for specific errors.
type TransferDirection ¶ added in v0.0.2
type TransferDirection int
TransferDirection represents the direction of a file transfer.
const ( // DownloadFromPeer transfer direction. DownloadFromPeer TransferDirection = iota // UploadToPeer transfer direction. UploadToPeer )
func (TransferDirection) String ¶ added in v1.0.0
func (i TransferDirection) String() string
type TransferRequest ¶ added in v1.0.0
type TransferRequest struct {
Direction TransferDirection
Token soul.Token
Filename string
FileSize uint64
}
TransferRequest code 40 this message is sent by a peer once they are ready to start uploading a file to us. A TransferResponse message is expected from the recipient, either allowing or rejecting the upload attempt.
This message was formerly used to send a download request (direction 0) as well, but Nicotine+ >= 3.0.3, Museek+ and the official clients use the QueueUpload peer message for this purpose today.
func (*TransferRequest) Deserialize ¶ added in v1.0.0
func (t *TransferRequest) Deserialize(reader io.Reader) error
func (TransferRequest) Serialize ¶ added in v1.0.0
func (TransferRequest) Serialize(direction TransferDirection, token soul.Token, filename string, filesize uint64) ([]byte, error)
type TransferResponse ¶ added in v1.0.0
TransferResponse code 41 response to TransferRequest. We (or the other peer) either agrees, or tells the reason for rejecting the file upload.
func (*TransferResponse) Deserialize ¶ added in v1.0.0
func (t *TransferResponse) Deserialize(reader io.Reader) error
func (TransferResponse) Serialize ¶ added in v1.0.0
Serialize accepts a TransferResponse and returns a message packed as a byte slice. If the transfer is not allowed, a reason must be provided. The possible errors are: ErrBanned, ErrCancelled, ErrComplete, ErrFileNotShared, ErrFileReadError, ErrPendingShutdown, ErrQueued, ErrTooManyFiles, ErrTooManyMegabytes, and ErrNotAllowedWithNoReason. All errors exist in the peer.TransferResponse package.
type UploadDenied ¶ added in v1.0.0
UploadDenied code 50 this message is sent to reject QueueUpload attempts and previously queued files. The reason for rejection will appear in the transfer list of the recipient.
func (*UploadDenied) Deserialize ¶ added in v1.0.0
func (u *UploadDenied) Deserialize(reader io.Reader) error
type UploadFailed ¶ added in v1.0.0
type UploadFailed struct {
Filename string
}
UploadFailed code 46 this message is sent whenever a file connection of an active upload closes. Soulseek NS clients can also send this message when a file cannot be read. The recipient either re-queues the upload (download on their end), or ignores the message if the transfer finished.
func (*UploadFailed) Deserialize ¶ added in v1.0.0
func (u *UploadFailed) Deserialize(reader io.Reader) error
type UploadPermission ¶ added in v0.0.2
type UploadPermission int
UploadPermission represents the permission level for uploading files.
const ( // NoOne permission level. NoOne UploadPermission = iota // Everyone permission level. Everyone // UsersInList permission level. UsersInList // PermittedUsers permission level. PermittedUsers )
func (UploadPermission) String ¶ added in v1.0.0
func (i UploadPermission) String() string
type UserInfoRequest ¶ added in v1.0.0
type UserInfoRequest struct{}
func (*UserInfoRequest) Deserialize ¶ added in v1.0.0
func (u *UserInfoRequest) Deserialize(reader io.Reader) error
func (UserInfoRequest) Serialize ¶ added in v1.0.0
func (UserInfoRequest) Serialize() ([]byte, error)
type UserInfoResponse ¶ added in v1.0.0
type UserInfoResponse struct {
Description string
Picture []byte
TotalUpload uint32
QueueSize uint32
FreeSlots bool
UploadPermitted UploadPermission
}
func (*UserInfoResponse) Deserialize ¶ added in v1.0.0
func (u *UserInfoResponse) Deserialize(reader io.Reader) error
func (UserInfoResponse) Serialize ¶ added in v1.0.0
func (UserInfoResponse) Serialize(u UserInfoResponse) ([]byte, error)
Source Files
¶
- code_string.go
- codeinit_string.go
- fileattributetype_string.go
- filesearchresponse.go
- foldercontentsrequest.go
- foldercontentsresponse.go
- peer.go
- peerinit.go
- piercefirewall.go
- placeinqueuerequest.go
- placeinqueueresponse.go
- queueupload.go
- sharedfileistresponse.go
- sharedfilelistrequest.go
- transferdirection_string.go
- transferrequest.go
- transferresponse.go
- uploaddenied.go
- uploadfailed.go
- uploadpermission_string.go
- userinforequest.go
- userinforesponse.go