Documentation ¶
Index ¶
- type AuthorizationManager
- type AutoConnectionHandler
- func (ach *AutoConnectionHandler) GetSupportedChannelTypes() []string
- func (ach *AutoConnectionHandler) Init()
- func (ach *AutoConnectionHandler) OnClosed(err error)
- func (ach *AutoConnectionHandler) OnOpenChannelRequest(ctype string) (channels.Handler, error)
- func (ach *AutoConnectionHandler) OnReady(oc *Connection)
- func (ach *AutoConnectionHandler) RegisterChannelHandler(ctype string, handler func() channels.Handler)
- type ChannelManager
- func (cm *ChannelManager) Channel(ctype string, way channels.Direction) *channels.Channel
- func (cm *ChannelManager) GetChannel(channelID int32) (*channels.Channel, bool)
- func (cm *ChannelManager) OpenChannelRequest(chandler channels.Handler) (*channels.Channel, error)
- func (cm *ChannelManager) OpenChannelRequestFromPeer(channelID int32, chandler channels.Handler) (*channels.Channel, error)
- func (cm *ChannelManager) RemoveChannel(channelID int32)
- type Connection
- func (rc *Connection) Break() error
- func (rc *Connection) Channel(ctype string, way channels.Direction) *channels.Channel
- func (rc *Connection) Close()
- func (rc *Connection) Do(do func() error) error
- func (rc *Connection) DoContext(ctx context.Context, do func(context.Context) error) error
- func (rc *Connection) EnableFeatures(features []string)
- func (rc *Connection) Process(handler Handler) error
- func (rc *Connection) RequestOpenChannel(ctype string, handler channels.Handler) (*channels.Channel, error)
- type ControlChannel
- func (ctrl *ControlChannel) Init(channelManager *ChannelManager)
- func (ctrl *ControlChannel) ProcessChannelResult(cr *Protocol_Data_Control.ChannelResult) (bool, error)
- func (ctrl *ControlChannel) ProcessEnableFeatures(handler Handler, ef *Protocol_Data_Control.EnableFeatures) []byte
- func (ctrl *ControlChannel) ProcessKeepAlive(ka *Protocol_Data_Control.KeepAlive) (bool, []byte)
- type Handler
- type InboundConnectionHandler
- type OutboundConnectionHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthorizationManager ¶
AuthorizationManager helps keep track of permissions for a connection
func (*AuthorizationManager) AddAuthorization ¶
func (am *AuthorizationManager) AddAuthorization(authz string)
AddAuthorization adds the string authz to the map of allowed authorizations
func (*AuthorizationManager) Authorized ¶
func (am *AuthorizationManager) Authorized(authz string) error
Authorized returns no error in the case an authz type is authorized, error otherwise.
func (*AuthorizationManager) Init ¶
func (am *AuthorizationManager) Init()
Init sets up an AuthorizationManager to be used.
type AutoConnectionHandler ¶
type AutoConnectionHandler struct {
// contains filtered or unexported fields
}
AutoConnectionHandler implements the ConnectionHandler interface on behalf of the provided application type by automatically providing support for any built-in channel type whose high level interface is implemented by the application. For example, if the application's type implements the ChatChannelHandler interface, `im.ricochet.chat` will be available to the peer.
The application handler can be any other type. To override or augment any of AutoConnectionHandler's behavior (such as adding new channel types, or reacting to connection close events), this type can be embedded in the type that it serves.
func (*AutoConnectionHandler) GetSupportedChannelTypes ¶
func (ach *AutoConnectionHandler) GetSupportedChannelTypes() []string
GetSupportedChannelTypes returns a list of channel types that are registered with the handler.
func (*AutoConnectionHandler) Init ¶
func (ach *AutoConnectionHandler) Init()
Init ... TODO: Split this into client and server init
func (*AutoConnectionHandler) OnClosed ¶
func (ach *AutoConnectionHandler) OnClosed(err error)
OnClosed is called when the OpenConnection has closed for any reason.
func (*AutoConnectionHandler) OnOpenChannelRequest ¶
func (ach *AutoConnectionHandler) OnOpenChannelRequest(ctype string) (channels.Handler, error)
OnOpenChannelRequest ...
func (*AutoConnectionHandler) OnReady ¶
func (ach *AutoConnectionHandler) OnReady(oc *Connection)
OnReady ...
func (*AutoConnectionHandler) RegisterChannelHandler ¶
func (ach *AutoConnectionHandler) RegisterChannelHandler(ctype string, handler func() channels.Handler)
RegisterChannelHandler ...
type ChannelManager ¶
type ChannelManager struct {
// contains filtered or unexported fields
}
ChannelManager encapsulates the logic for server and client side assignment and removal of channels.
func NewClientChannelManager ¶
func NewClientChannelManager() *ChannelManager
NewClientChannelManager construsts a new channel manager enforcing behaviour of a ricochet client
func NewServerChannelManager ¶
func NewServerChannelManager() *ChannelManager
NewServerChannelManager construsts a new channel manager enforcing behaviour from a ricochet server
func (*ChannelManager) Channel ¶
Channel finds an open or pending `type` channel in the direction `way` (Inbound or Outbound), and returns the associated state. Returns nil if no matching channel exists or if multiple matching channels exist.
func (*ChannelManager) GetChannel ¶
func (cm *ChannelManager) GetChannel(channelID int32) (*channels.Channel, bool)
GetChannel finds and returns a given channel if it is found
func (*ChannelManager) OpenChannelRequest ¶
OpenChannelRequest constructs a channel type ready for processing given a request from the client.
func (*ChannelManager) OpenChannelRequestFromPeer ¶
func (cm *ChannelManager) OpenChannelRequestFromPeer(channelID int32, chandler channels.Handler) (*channels.Channel, error)
OpenChannelRequestFromPeer constructs a channel type ready for processing given a request from the remote peer.
func (*ChannelManager) RemoveChannel ¶
func (cm *ChannelManager) RemoveChannel(channelID int32)
RemoveChannel removes a given channel id.
type Connection ¶
type Connection struct { utils.RicochetNetwork IsInbound bool RemoteHostname string SupportChannels []string // contains filtered or unexported fields }
Connection encapsulates the state required to maintain a connection to a ricochet service.
func NewInboundConnection ¶
func NewInboundConnection(conn io.ReadWriteCloser) *Connection
NewInboundConnection creates a new Connection struct modelling an Inbound Connection
func NewOutboundConnection ¶
func NewOutboundConnection(conn io.ReadWriteCloser, remoteHostname string) *Connection
NewOutboundConnection creates a new Connection struct modelling an Inbound Connection
func (*Connection) Break ¶
func (rc *Connection) Break() error
Break causes Process() to return, but does not close the underlying connection Break returns an error if it would not be valid to call Process() again for the connection now. Currently, the only such error is ConnectionClosedError.
func (*Connection) Channel ¶
Channel is a convienciance method for returning a given channel to the caller of Process() - TODO - this is kind of ugly.
func (*Connection) Close ¶
func (rc *Connection) Close()
Close tearsdown a Process() and explicitly Closes the connection. Note, that if Process() is holding a connection this will trigger an Error
func (*Connection) Do ¶
func (rc *Connection) Do(do func() error) error
Do allows any function utilizing Connection to be run safely, if you're careful. All operations which require access (directly or indirectly) to Connection while Process is running need to use Do. Calls to Do without Process running will block unless the connection is closed, which is returned as ConnectionClosedError.
Like a mutex, Do cannot be called recursively. This will deadlock. As a result, no API in this library that can be reached from the application should use Do, with few exceptions. This would make the API impossible to use safely in many cases.
Do is safe to call from methods of connection.Handler and channel.Handler that are called by Process.
func (*Connection) DoContext ¶
DoContext behaves in the same way as Do, but also respects the provided context when blocked, and passes the context to the callback function.
DoContext should be used when any call to Do may need to be cancelled or timed out.
func (*Connection) EnableFeatures ¶
func (rc *Connection) EnableFeatures(features []string)
EnableFeatures sends an EnableFeatures messages which includes the list of `features`
func (*Connection) Process ¶
func (rc *Connection) Process(handler Handler) error
Process receives socket and protocol events for the connection. Methods of the application-provided `handler` will be called from this goroutine for all events.
Process must be running in order to handle any events on the connection, including connection close.
Process blocks until the connection is closed or until Break() is called. Infof the connection is closed, a non-nil error is returned.
func (*Connection) RequestOpenChannel ¶
func (rc *Connection) RequestOpenChannel(ctype string, handler channels.Handler) (*channels.Channel, error)
RequestOpenChannel sends an OpenChannel message to the remote client. An error is returned only if the requirements for opening this channel are not met on the local side (a nil error return does not mean the channel was opened successfully, because channels open asynchronously).
type ControlChannel ¶
type ControlChannel struct {
// contains filtered or unexported fields
}
ControlChannel encapsulates logic for the control channel processing
func (*ControlChannel) Init ¶
func (ctrl *ControlChannel) Init(channelManager *ChannelManager)
Init sets up a control channel
func (*ControlChannel) ProcessChannelResult ¶
func (ctrl *ControlChannel) ProcessChannelResult(cr *Protocol_Data_Control.ChannelResult) (bool, error)
ProcessChannelResult contains the logic for processing a channelresult message
func (*ControlChannel) ProcessEnableFeatures ¶
func (ctrl *ControlChannel) ProcessEnableFeatures(handler Handler, ef *Protocol_Data_Control.EnableFeatures) []byte
ProcessEnableFeatures correctly handles a features enabled packet
func (*ControlChannel) ProcessKeepAlive ¶
func (ctrl *ControlChannel) ProcessKeepAlive(ka *Protocol_Data_Control.KeepAlive) (bool, []byte)
ProcessKeepAlive contains logic for responding to keep alives
type Handler ¶
type Handler interface { // OnReady is called when the connection begins using this handler. OnReady(oc *Connection) // OnClosed is called when the OpenConnection has closed for any reason. OnClosed(err error) // OpenChannelRequest is called when the peer asks to open a channel of // `type`. `raw` contains the protocol OpenChannel message including any // extension data. If this channel type is recognized and allowed by this // connection in this state, return a type implementing ChannelHandler for // events related to this channel. Returning an error or nil rejects the // channel. // // Channel type handlers may implement additional state and sanity checks. // A non-nil return from this function does not guarantee that the channel // will be opened. OnOpenChannelRequest(ctype string) (channels.Handler, error) GetSupportedChannelTypes() []string }
Handler reacts to low-level events on a protocol connection. There should be a unique instance of a ConnectionHandler type per OpenConnection.
type InboundConnectionHandler ¶
type InboundConnectionHandler struct {
// contains filtered or unexported fields
}
InboundConnectionHandler is a convieniance wrapper for handling inbound connections
func HandleInboundConnection ¶
func HandleInboundConnection(c *Connection) *InboundConnectionHandler
HandleInboundConnection returns an InboundConnectionHandler given a connection
func (*InboundConnectionHandler) ProcessAuthAsV3Server ¶
func (ich *InboundConnectionHandler) ProcessAuthAsV3Server(v3identity identity.Identity, sach func(hostname string, publicKey ed25519.PublicKey) (allowed, known bool)) error
ProcessAuthAsV3Server blocks until authentication has succeeded, failed, or the connection is closed. A non-nil error is returned in all cases other than successful and accepted authentication.
ProcessAuthAsV3Server cannot be called at the same time as any other call to a Process function. Another Process function must be called after this function successfully returns to continue handling connection events.
The acceptCallback function is called after receiving a valid authentication proof with the client's authenticated hostname and public key. acceptCallback must return true to accept authentication and allow the connection to continue, and also returns a boolean indicating whether the contact is known and recognized. Unknown contacts will assume they are required to send a contact request before any other activity.
type OutboundConnectionHandler ¶
type OutboundConnectionHandler struct {
// contains filtered or unexported fields
}
OutboundConnectionHandler is a convieniance wrapper for handling outbound connections
func HandleOutboundConnection ¶
func HandleOutboundConnection(c *Connection) *OutboundConnectionHandler
HandleOutboundConnection returns an OutboundConnectionHandler given a connection
func (*OutboundConnectionHandler) ProcessAuthAsV3Client ¶
func (och *OutboundConnectionHandler) ProcessAuthAsV3Client(v3identity identity.Identity) (bool, error)
ProcessAuthAsV3Client blocks until authentication has succeeded or failed with the provided identity, or the connection is closed. A non-nil error is returned in all cases other than successful authentication.
ProcessAuthAsV3Client cannot be called at the same time as any other call to a Process function. Another Process function must be called after this function successfully returns to continue handling connection events.
For successful authentication, the `known` return value indicates whether the peer accepts us as a known contact. Unknown contacts will generally need to send a contact request before any other activity.