Documentation
¶
Index ¶
- Constants
- func SendMessageOnChatChannel(channel *Channel, message string) (uint32, error)
- type Channel
- type ChatChannel
- func (cc *ChatChannel) Acknowledge(messageID uint32, accepted bool)
- func (cc *ChatChannel) Bidirectional() bool
- func (cc *ChatChannel) Closed(err error)
- func (cc *ChatChannel) OnlyClientCanOpen() bool
- func (cc *ChatChannel) OpenInbound(channel *Channel, raw *Protocol_Data_Control.OpenChannel) ([]byte, error)
- func (cc *ChatChannel) OpenOutbound(channel *Channel) ([]byte, error)
- func (cc *ChatChannel) OpenOutboundResult(err error, crm *Protocol_Data_Control.ChannelResult)
- func (cc *ChatChannel) Packet(data []byte)
- func (cc *ChatChannel) RequiresAuthentication() string
- func (cc *ChatChannel) SendMessage(message string) uint32
- func (cc *ChatChannel) SendMessageWithTime(message string, when time.Time) uint32
- func (cc *ChatChannel) Singleton() bool
- func (cc *ChatChannel) Type() string
- type ChatChannelHandler
- type ContactRequestChannel
- func (crc *ContactRequestChannel) Bidirectional() bool
- func (crc *ContactRequestChannel) Closed(err error)
- func (crc *ContactRequestChannel) OnlyClientCanOpen() bool
- func (crc *ContactRequestChannel) OpenInbound(channel *Channel, oc *Protocol_Data_Control.OpenChannel) ([]byte, error)
- func (crc *ContactRequestChannel) OpenOutbound(channel *Channel) ([]byte, error)
- func (crc *ContactRequestChannel) OpenOutboundResult(err error, crm *Protocol_Data_Control.ChannelResult)
- func (crc *ContactRequestChannel) Packet(data []byte)
- func (crc *ContactRequestChannel) RequiresAuthentication() string
- func (crc *ContactRequestChannel) SendResponse(status string)
- func (crc *ContactRequestChannel) Singleton() bool
- func (crc *ContactRequestChannel) Type() string
- type ContactRequestChannelHandler
- type Direction
- type Handler
Constants ¶
const ( InvalidContactNameError = utils.Error("InvalidContactNameError") InvalidContactMessageError = utils.Error("InvalidContactMessageError") InvalidContactRequestError = utils.Error("InvalidContactRequestError") )
Defining Versions
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Channel ¶
type Channel struct {
ID int32
Type string
Direction Direction
Handler Handler
Pending bool
ServerHostname string
ClientHostname string
// Functions for updating the underlying Connection
SendMessage func([]byte)
CloseChannel func()
DelegateAuthorization func()
DelegateEncryption func([32]byte)
}
Channel holds the state of a channel on an open connection
type ChatChannel ¶
type ChatChannel struct {
// Methods of Handler are called for chat events on this channel
Handler ChatChannelHandler
// contains filtered or unexported fields
}
ChatChannel implements the ChannelHandler interface for a channel of type "im.ricochet.chat". The channel may be inbound or outbound.
ChatChannel implements protocol-level sanity and state validation, but does not handle or acknowledge chat messages. The application must provide a ChatChannelHandler implementation to handle chat events.
func (*ChatChannel) Acknowledge ¶
func (cc *ChatChannel) Acknowledge(messageID uint32, accepted bool)
Acknowledge indicates that the given messageID was received, and whether it was accepted.
func (*ChatChannel) Bidirectional ¶
func (cc *ChatChannel) Bidirectional() bool
Bidirectional - for chat channels are not bidrectional
func (*ChatChannel) Closed ¶
func (cc *ChatChannel) Closed(err error)
Closed is called when the channel is closed for any reason.
func (*ChatChannel) OnlyClientCanOpen ¶
func (cc *ChatChannel) OnlyClientCanOpen() bool
OnlyClientCanOpen - for chat channels any side can open
func (*ChatChannel) OpenInbound ¶
func (cc *ChatChannel) OpenInbound(channel *Channel, raw *Protocol_Data_Control.OpenChannel) ([]byte, error)
OpenInbound is the first method called for an inbound channel request. If an error is returned, the channel is rejected. If a RawMessage is returned, it will be sent as the ChannelResult message.
func (*ChatChannel) OpenOutbound ¶
func (cc *ChatChannel) OpenOutbound(channel *Channel) ([]byte, error)
OpenOutbound is the first method called for an outbound channel request. If an error is returned, the channel is not opened. If a RawMessage is returned, it will be sent as the OpenChannel message.
func (*ChatChannel) OpenOutboundResult ¶
func (cc *ChatChannel) OpenOutboundResult(err error, crm *Protocol_Data_Control.ChannelResult)
OpenOutboundResult is called when a response is received for an outbound OpenChannel request. If `err` is non-nil, the channel was rejected and Closed will be called immediately afterwards. `raw` contains the raw protocol message including any extension data.
func (*ChatChannel) Packet ¶
func (cc *ChatChannel) Packet(data []byte)
Packet is called for each raw packet received on this channel.
func (*ChatChannel) RequiresAuthentication ¶
func (cc *ChatChannel) RequiresAuthentication() string
RequiresAuthentication - chat channels require hidden service auth
func (*ChatChannel) SendMessage ¶
func (cc *ChatChannel) SendMessage(message string) uint32
SendMessage sends a given message using this channel, and returns the messageID, which will be used in ChatMessageAck when the peer acknowledges this message.
func (*ChatChannel) SendMessageWithTime ¶
func (cc *ChatChannel) SendMessageWithTime(message string, when time.Time) uint32
SendMessageWithTime is identical to SendMessage, but also sends the provided time.Time as a rough timestamp for when this message was originally sent. This should be used when retrying or sending queued messages.
func (*ChatChannel) Singleton ¶
func (cc *ChatChannel) Singleton() bool
Singleton - for chat channels there can only be one instance per direction
func (*ChatChannel) Type ¶
func (cc *ChatChannel) Type() string
Type returns the type string for this channel, e.g. "im.ricochet.chat".
type ChatChannelHandler ¶
type ChatChannelHandler interface {
// OpenInbound is called when a inbound chat channel is opened
OpenInbound()
// ChatMessage is called when a chat message is received. Return true to acknowledge
// the message successfully, and false to NACK and refuse the message.
ChatMessage(messageID uint32, when time.Time, message string) bool
// ChatMessageAck is called when an acknowledgement of a sent message is received.
ChatMessageAck(messageID uint32, accepted bool)
}
ChatChannelHandler is implemented by an application type to receive events from a ChatChannel.
Note that ChatChannelHandler is composable with other interfaces, including ConnectionHandler; there is no need to use a distinct type as a ChatChannelHandler.
type ContactRequestChannel ¶
type ContactRequestChannel struct {
// Methods of Handler are called for chat events on this channel
Handler ContactRequestChannelHandler
// Properties of the request
Name string
Message string
// contains filtered or unexported fields
}
ContactRequestChannel implements the ChannelHandler interface for a channel of type "im.ricochet.contact.request". The channel may be inbound or outbound.
func (*ContactRequestChannel) Bidirectional ¶
func (crc *ContactRequestChannel) Bidirectional() bool
Bidirectional - only clients can send messages
func (*ContactRequestChannel) Closed ¶
func (crc *ContactRequestChannel) Closed(err error)
Closed is called when the channel is closed for any reason.
func (*ContactRequestChannel) OnlyClientCanOpen ¶
func (crc *ContactRequestChannel) OnlyClientCanOpen() bool
OnlyClientCanOpen - only clients can open contact requests
func (*ContactRequestChannel) OpenInbound ¶
func (crc *ContactRequestChannel) OpenInbound(channel *Channel, oc *Protocol_Data_Control.OpenChannel) ([]byte, error)
OpenInbound is the first method called for an inbound channel request. If an error is returned, the channel is rejected. If a RawMessage is returned, it will be sent as the ChannelResult message.
func (*ContactRequestChannel) OpenOutbound ¶
func (crc *ContactRequestChannel) OpenOutbound(channel *Channel) ([]byte, error)
OpenOutbound is the first method called for an outbound channel request. If an error is returned, the channel is not opened. If a RawMessage is returned, it will be sent as the OpenChannel message.
func (*ContactRequestChannel) OpenOutboundResult ¶
func (crc *ContactRequestChannel) OpenOutboundResult(err error, crm *Protocol_Data_Control.ChannelResult)
OpenOutboundResult is called when a response is received for an outbound OpenChannel request. If `err` is non-nil, the channel was rejected and Closed will be called immediately afterwards. `raw` contains the raw protocol message including any extension data.
func (*ContactRequestChannel) Packet ¶
func (crc *ContactRequestChannel) Packet(data []byte)
Packet is called for each raw packet received on this channel.
func (*ContactRequestChannel) RequiresAuthentication ¶
func (crc *ContactRequestChannel) RequiresAuthentication() string
RequiresAuthentication - contact requests require hidden service auth
func (*ContactRequestChannel) SendResponse ¶
func (crc *ContactRequestChannel) SendResponse(status string)
SendResponse sends a contact request status response to the requester.
func (*ContactRequestChannel) Singleton ¶
func (crc *ContactRequestChannel) Singleton() bool
Singleton - only one contact request can be opened per side
func (*ContactRequestChannel) Type ¶
func (crc *ContactRequestChannel) Type() string
Type returns the type string for this channel, e.g. "im.ricochet.chat".
type ContactRequestChannelHandler ¶
type ContactRequestChannelHandler interface {
ContactRequest(name string, message string) string
ContactRequestRejected()
ContactRequestAccepted()
ContactRequestError()
}
ContactRequestChannelHandler is implemented by an application type to receive events from a ContactRequestChannel.
Note that ContactRequestChannelHandler is composable with other interfaces, including ConnectionHandler; there is no need to use a distinct type as a ContactRequestChannelHandler.
type Direction ¶
type Direction int
Direction indicated whether we or the remote peer opened the channel
type Handler ¶
type Handler interface {
// Type returns the type string for this channel, e.g. "im.ricochet.chat".
Type() string
// Closed is called when the channel is closed for any reason.
Closed(err error)
// OnlyClientCanOpen indicates if only a client can open a given channel
OnlyClientCanOpen() bool
// Singleton indicates if a channel can only have one instance per direction
Singleton() bool
// Bidirectional indicates if messages can be send by either side
Bidirectional() bool
// RequiresAuthentication describes what authentication is needed for the channel
RequiresAuthentication() string
// OpenInbound is the first method called for an inbound channel request.
// If an error is returned, the channel is rejected. If a RawMessage is
// returned, it will be sent as the ChannelResult message.
OpenInbound(channel *Channel, raw *Protocol_Data_Control.OpenChannel) ([]byte, error)
// OpenOutbound is the first method called for an outbound channel request.
// If an error is returned, the channel is not opened. If a RawMessage is
// returned, it will be sent as the OpenChannel message.
OpenOutbound(channel *Channel) ([]byte, error)
// OpenOutboundResult is called when a response is received for an
// outbound OpenChannel request. If `err` is non-nil, the channel was
// rejected and Closed will be called immediately afterwards. `raw`
// contains the raw protocol message including any extension data.
OpenOutboundResult(err error, raw *Protocol_Data_Control.ChannelResult)
// Packet is called for each raw packet received on this channel.
Packet(data []byte)
}
Handler reacts to low-level events on a protocol channel. There should be a unique instance of a ChannelHandler type per channel.
Applications generally don't need to implement ChannelHandler directly; instead, use the built-in implementations for common channel types, and their individual callback interfaces. ChannelHandler is useful when implementing new channel types, or modifying low level default behavior.