Documentation ¶
Index ¶
- type Client
- func (c *Client) Addr() string
- func (c *Client) Id() string
- func (c *Client) Members() []string
- func (c *Client) OpenStream(dest string) (chan []byte, chan []byte)
- func (c *Client) RegisterGossipHandler(gossipHandler func([]byte) ([]byte, error))
- func (c *Client) RegisterMsgHandler(msgHandler func([]byte) ([]byte, error))
- func (c *Client) RegisterResponseHandler(responseHandler func([]byte))
- func (c *Client) RegisterStreamHandler(streamHandler func(chan []byte, chan []byte))
- func (c *Client) SaveCertificate() error
- func (c *Client) SavePrivateKey() error
- func (c *Client) SendTo(dest string, data []byte) chan *core.Message
- func (c *Client) SendToId(destId []byte, data []byte) (chan *core.Message, error)
- func (c *Client) SetGossipContent(data []byte) error
- func (c *Client) Sign(content []byte) ([]byte, []byte, error)
- func (c *Client) Start()
- func (c *Client) Stop()
- func (c *Client) VerifySignature(r, s, content []byte, id string) bool
- type Config
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) Addr ¶
Returns the address(ip:port) of the ifrit client. Can be directly used as entry addresses in the config.
func (*Client) Members ¶
Returns the address (ip:port, rpc endpoint) of all other ifrit clients in the network which is currently believed to be alive.
func (*Client) OpenStream ¶
Returns a pair of channels used for bi-directional streams, given the destination. The first channel is the input stream to the server and the second stream is the reply stream from the server. To close the stream, close the input channel. The reply stream is open as long as the server sends messages back to the client. The caller must ensure that the reply stream does not block by draining the buffer so that the stream session can complete. Note: it is adviced to implement an aknowledgement mechanism to avoid an untimely closing of a channel and loss of messages.
func (*Client) RegisterGossipHandler ¶
Registers the given function as the gossip handler. Invoked each time ifrit receives application gossip. The returned byte slice will be sent back as the response. If the callback returns a non-nil error, it will be sent back as the response instead.
func (*Client) RegisterMsgHandler ¶
Registers the given function as the message handler. Invoked each time the ifrit client receives an application message (another client sent it through SendTo), this callback will be invoked. The returned byte slice will be sent back as the response. If error is non-nil, it will be returned as the response. All responses will be received on the sending side through a channel, see SendTo documentation for details.
func (*Client) RegisterResponseHandler ¶
Registers the given function as the gossip response handler. Invoked when ifrit receives a response after gossiping application data. All responses originates from a gossip handler invocation. If the ResponseHandler is not registered or nil, responses will be discarded.
func (*Client) RegisterStreamHandler ¶
Registers the given function as the stream handler. Invoked when the client opens a stream. The callback accepts two channels - an unbuffered input channel and an unbuffered channel used for replying to the client. The caller must close the reply channel to signal that the stream is closing. See the note in OpenStream().
func (*Client) SaveCertificate ¶
func (*Client) SavePrivateKey ¶
func (*Client) SendTo ¶
Sends the given data to the given destination. The caller must ensure that the given data is not modified after calling this function. The returned channel will be populated with the response. The data and error values are contained in the *core.Message type. If the destination could not be reached or timeout occurs, nil will be sent through the channel. The response data can be safely modified after receiving it. The message instance is nil if the recipient is unavailable. Ifrit will close the channel after receiving the response message.
func (*Client) SendToId ¶
Same as SendTo, but destination is now the Ifrit id of the receiver. Returns an error if no observed peer has the specified destination id.
func (*Client) SetGossipContent ¶
Replaces the gossip set with the given data. This data will be exchanged with neighbors in each gossip interaction. Recipients will receive it through the message handler callback. The response generated by the message handler callback will be sent back and invoke the response handler callback.
func (*Client) Stop ¶
func (c *Client) Stop()
Stops client operations. The client cannot be used after callling Close.
func (*Client) VerifySignature ¶
Checks if the given content is correctly signed by the public key belonging to the given node id. The id represents another node in the Fireflies network, if the id is not recongnized false is returned.
type Config ¶
type Config struct { // If set to true, the client will create new cryptographic resources and store it in // CryptoUnitPath. Otherwise, it will use the existing resources. New bool // TCP port of the Ifrit client. TCPPort int // UDP port of the Ifrit client. UDPPort int // Hostname used in the X.509 certificate. Hostname string // The directory of the cryptographic resources. CryptoUnitPath string }