Documentation ¶
Overview ¶
package inet256ipc provides a generic client and server for using an inet256.Service across process boundaries.
Index ¶
- Constants
- func NewRequestID() (ret [16]byte)
- func ServeNode(ctx context.Context, node inet256.Node, framer Framer, opts ...ServeNodeOption) error
- func WriteAskMessage(fr *Frame, reqID [16]byte, mtype MessageType, x any)
- func WriteDataMessage(fr *Frame, addr inet256.Addr, data []byte)
- func WriteError[T any](fr *Frame, reqID [16]byte, mtype MessageType, err error)
- func WriteKeepAlive(fr *Frame)
- func WriteRequest(fr *Frame, reqID [16]byte, mtype MessageType, x any)
- func WriteSuccess[T any](fr *Frame, reqID [16]byte, mtype MessageType, x T)
- type DataMsg
- type FindAddrReq
- type FindAddrRes
- type Frame
- type Framer
- type LookupPublicKeyReq
- type LookupPublicKeyRes
- type MTUReq
- type MTURes
- type Message
- func (m Message) AskBody() []byte
- func (m Message) DataAddrBytes() []byte
- func (m Message) DataMsg() DataMsg
- func (m Message) DataPayload() []byte
- func (m Message) FindAddrReq() (*FindAddrReq, error)
- func (m Message) FindAddrRes() (*FindAddrRes, error)
- func (m Message) GetRequestID() (ret [16]byte)
- func (m Message) GetType() MessageType
- func (m Message) IsAsk() bool
- func (m Message) IsTell() bool
- func (m Message) LookupPublicKeyReq() (*LookupPublicKeyReq, error)
- func (m Message) LookupPublicKeyRes() (*LookupPublicKeyRes, error)
- func (m Message) MTUReq() (*MTUReq, error)
- func (m Message) MTURes() (*MTURes, error)
- func (m Message) SetRequestID(id [16]byte)
- func (m Message) SetType(mt MessageType)
- type MessageType
- type NodeClient
- func (c *NodeClient) Close() error
- func (c *NodeClient) FindAddr(ctx context.Context, prefix []byte, nbits int) (inet256.Addr, error)
- func (c *NodeClient) LocalAddr() inet256.Addr
- func (c *NodeClient) LookupPublicKey(ctx context.Context, target inet256.Addr) (inet256.PublicKey, error)
- func (c *NodeClient) MTU(ctx context.Context, target inet256.Addr) int
- func (c *NodeClient) PublicKey() inet256.PublicKey
- func (c *NodeClient) Receive(ctx context.Context, fn inet256.ReceiveFunc) error
- func (c *NodeClient) Send(ctx context.Context, dst inet256.Addr, data []byte) error
- type NodeClientOption
- type Response
- type ServeNodeOption
- type StreamFramer
Constants ¶
View Source
const ( // MaxFrameLen is the maximum length of a frame on the wire MaxFrameLen = 4 + MaxMessageLen // MaxFrameBodyLen is the maximum length of the body of a frame. MaxFrameBodyLen = MaxMessageLen )
View Source
const ( DefaultKeepAliveInterval = 1 * time.Second DefaultKeepAliveTimeout = 3 * time.Second )
View Source
const ( MT_Data = MessageType('D'<<24 | 'A'<<16 | 'T'<<8 | 'A') MT_PublicKey = MessageType('P'<<24 | 'U'<<16 | 'B'<<8 | 'K') MT_FindAddr = MessageType('F'<<24 | 'I'<<16 | 'N'<<8 | 'D') MT_MTU = MessageType('M'<<24 | 'T'<<16 | 'U'<<8 | '_') MT_KeepAlive = MessageType('K'<<24 | 'E'<<16 | 'E'<<8 | 'P') )
View Source
const ( MaxMessageLen = 4 + 32 + inet256.MaxMTU MinMessageLen = 4 ReqIDLen = 16 MinDataMsgLen = MinMessageLen + 32 MinAskMsgLen = MinMessageLen + ReqIDLen )
Variables ¶
This section is empty.
Functions ¶
func NewRequestID ¶
func NewRequestID() (ret [16]byte)
func ServeNode ¶
func ServeNode(ctx context.Context, node inet256.Node, framer Framer, opts ...ServeNodeOption) error
ServeNode reads and writes packets from a Framer, using the node to send network data and answer requests. If the context is cancelled ServeNode returns nil.
func WriteAskMessage ¶
func WriteAskMessage(fr *Frame, reqID [16]byte, mtype MessageType, x any)
func WriteDataMessage ¶
WriteDataMessage places a message in the frame
func WriteError ¶
func WriteError[T any](fr *Frame, reqID [16]byte, mtype MessageType, err error)
func WriteKeepAlive ¶
func WriteKeepAlive(fr *Frame)
func WriteRequest ¶
func WriteRequest(fr *Frame, reqID [16]byte, mtype MessageType, x any)
func WriteSuccess ¶
func WriteSuccess[T any](fr *Frame, reqID [16]byte, mtype MessageType, x T)
Types ¶
type FindAddrReq ¶
type FindAddrRes ¶
type Frame ¶
type Frame struct {
// contains filtered or unexported fields
}
Frame is a length-prefixed frame suitable for transmitting messages over a stream.
type LookupPublicKeyReq ¶
type LookupPublicKeyRes ¶
type LookupPublicKeyRes struct {
PublicKey []byte `json:"public_key,omitempty"`
}
type Message ¶
type Message []byte
func (Message) DataAddrBytes ¶
func (Message) DataPayload ¶
func (Message) FindAddrReq ¶
func (m Message) FindAddrReq() (*FindAddrReq, error)
func (Message) FindAddrRes ¶
func (m Message) FindAddrRes() (*FindAddrRes, error)
func (Message) GetRequestID ¶
func (Message) GetType ¶
func (m Message) GetType() MessageType
func (Message) LookupPublicKeyReq ¶
func (m Message) LookupPublicKeyReq() (*LookupPublicKeyReq, error)
func (Message) LookupPublicKeyRes ¶
func (m Message) LookupPublicKeyRes() (*LookupPublicKeyRes, error)
func (Message) SetRequestID ¶
func (Message) SetType ¶
func (m Message) SetType(mt MessageType)
type MessageType ¶
type MessageType uint32
type NodeClient ¶
type NodeClient struct {
// contains filtered or unexported fields
}
func NewNodeClient ¶
func NewNodeClient(fr Framer, localPubKey inet256.PublicKey, opts ...NodeClientOption) *NodeClient
NewNodeClient returns a client which will read and write from rwc in the background
func (*NodeClient) Close ¶
func (c *NodeClient) Close() error
func (*NodeClient) LocalAddr ¶
func (c *NodeClient) LocalAddr() inet256.Addr
func (*NodeClient) LookupPublicKey ¶
func (*NodeClient) PublicKey ¶
func (c *NodeClient) PublicKey() inet256.PublicKey
func (*NodeClient) Receive ¶
func (c *NodeClient) Receive(ctx context.Context, fn inet256.ReceiveFunc) error
type NodeClientOption ¶
type NodeClientOption func(*clientConfig)
type ServeNodeOption ¶
type ServeNodeOption func(c *serveNodeConfig)
type StreamFramer ¶
type StreamFramer struct {
// contains filtered or unexported fields
}
func NewStreamFramer ¶
func NewStreamFramer(r io.Reader, w io.Writer) *StreamFramer
func (*StreamFramer) ReadFrame ¶
func (sf *StreamFramer) ReadFrame(ctx context.Context, fr *Frame) error
func (*StreamFramer) WriteFrame ¶
func (sf *StreamFramer) WriteFrame(ctx context.Context, fr *Frame) error
Click to show internal directories.
Click to hide internal directories.