twine

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2021 License: MIT Imports: 12 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

type Message struct {
	// contains filtered or unexported fields
}

Message encapsulates a generic message interface

func (*Message) CommandID

func (m *Message) CommandID() int

CommandID returns the command id

func (*Message) Error

func (m *Message) Error() error

Error returns an error if the reply was an error

func (*Message) GetRefRequestsChan

func (m *Message) GetRefRequestsChan() chan ReceivedMessageI

GetRefRequestsChan creates a channel if necessary and returns it

func (*Message) MsgID

func (m *Message) MsgID() int

MsgID returns the message id

func (*Message) OK

func (m *Message) OK() bool

OK checks if the reply was a simple OK

func (*Message) Payload

func (m *Message) Payload() []byte

Payload returns a pointer to the payload

func (*Message) RefMsgID

func (m *Message) RefMsgID() int

RefMsgID returns the reference message id

func (*Message) RefSend

func (m *Message) RefSend(cmd int, payload []byte) (SentMessageI, error)

RefSend creates a new message with a reference to the current message

func (*Message) RefSendBlock

func (m *Message) RefSendBlock(cmd int, payload []byte) (ReceivedReplyI, error)

RefSendBlock sends a new mssage referencing anexisting one, and returns with the response or an error

func (*Message) Reply

func (m *Message) Reply(cmd int, payload []byte) error

Reply to message This blocks until the other side returns OK or error

func (*Message) SendError

func (m *Message) SendError(errStr string) error

SendError sends the error code along with description

func (*Message) SendOK

func (m *Message) SendOK() error

SendOK sends an OK and closes the message

func (*Message) ServiceID

func (m *Message) ServiceID() int

ServiceID returns the service id

func (*Message) WaitReply

func (m *Message) WaitReply() (ReceivedReplyI, error)

WaitReply returns the reply or error when it eventually arrives

type MessageGetReplyI

type MessageGetReplyI interface {
	WaitReply() (ReceivedReplyI, error)
}

MessageGetReplyI adds the ability to wait for the reply to a sent message

type MessageI

type MessageI interface {
	MsgID() int
	RefMsgID() int
	CommandID() int
	ServiceID() int
	Payload() []byte
}

MessageI is the baseinterface for all Twine message interfaces

type MessageReceivedOKI

type MessageReceivedOKI interface {
	OK() bool
	Error() error
}

MessageReceivedOKI adds getters for OK and Error replies

type MessageRefererI

type MessageRefererI interface {
	RefSend(int, []byte) (SentMessageI, error)
	RefSendBlock(int, []byte) (ReceivedReplyI, error)
	GetRefRequestsChan() chan ReceivedMessageI
}

MessageRefererI adds the abilty to send and receive new Requests that reference the message

type MessageReplierI

type MessageReplierI interface {
	Reply(int, []byte) error
}

MessageReplierI adds teh ability to reply to an incoming message

type MessageReplyOKErrI

type MessageReplyOKErrI interface {
	SendOK() error
	SendError(string) error
}

MessageReplyOKErrI adds the ability to reply with OK and (someday) Error This can be a reply to an incoming messgae or to a reply.

type ReceivedMessageI

type ReceivedMessageI interface {
	MessageI
	MessageReplierI
	MessageReplyOKErrI
	MessageRefererI
}

ReceivedMessageI is a message that was initiated on the other side and received here You can reply or create new requests referring the message

type ReceivedReplyI

type ReceivedReplyI interface {
	MessageI
	MessageReceivedOKI
	MessageReplyOKErrI
}

ReceivedReplyI is a message received in response to a message sent You can acknowledge with an OK or error.

type SentMessageI

type SentMessageI interface {
	MessageI
	MessageGetReplyI
	MessageRefererI
}

SentMessageI is a mesage that was just sent and has the ability to makeadditional requests refering this message, and wait for replies

type Twine

type Twine struct {
	ReadyChan   chan struct{}
	MessageChan chan ReceivedMessageI
	ErrorChan   chan error
	// contains filtered or unexported fields
}

Twine holds everything needed for the protocol to function

func NewUnixClient

func NewUnixClient(sockPath string) *Twine

NewUnixClient creates a new Twine struct configured to be a client

func NewUnixServer

func NewUnixServer(sockPath string) (*Twine, error)

NewUnixServer creates a new Twine struct configured to be a server This returns once server is listening; use ReadyChan to know when a handshake has been made

func NewWebsocketServer

func NewWebsocketServer(res http.ResponseWriter, req *http.Request) (*Twine, error)

NewWebsocketServer returns a Twine instance from an http request

func (*Twine) Graceful

func (t *Twine) Graceful()

Graceful stops new incoming requests and waits for all messages to terminate before shutting down.

func (*Twine) RefRequest

func (t *Twine) RefRequest(refID int, cmd int, payload []byte) (SentMessageI, error)

RefRequest sneds a new message with a reference to an open message

func (*Twine) RefRequestBlock

func (t *Twine) RefRequestBlock(refID int, cmd int, payload []byte) (ReceivedReplyI, error)

RefRequestBlock sends a new message with a reference to an open message and blocks until a reply is received

func (*Twine) Reply

func (t *Twine) Reply(msgID int, cmd int, payload []byte) error

Reply to a message

func (*Twine) ReplyClose

func (t *Twine) ReplyClose(msgID int, ok bool, errStr string) error

ReplyClose sends an OK and closes the message

func (*Twine) Send

func (t *Twine) Send(servInt int, cmd int, payload []byte) (SentMessageI, error)

Send a new message Shouldn't you get a callback, or should you pass a callback?

func (*Twine) SendBlock

func (t *Twine) SendBlock(servInt int, cmd int, payload []byte) (ReceivedReplyI, error)

SendBlock sends a message and waits for the response before returning An error is returned iw the other side sent an error code.

func (*Twine) Stop

func (t *Twine) Stop()

Stop kills twine without trying to be nice about it.

func (*Twine) WaitClose

func (t *Twine) WaitClose()

WaitClose blocks until the twine connection closes

type Unix

type Unix struct {
	// contains filtered or unexported fields
}

Unix is the unix domain socket transport for Twine

func (*Unix) Close

func (u *Unix) Close()

Close the conn and listener

func (*Unix) ReadMessage

func (u *Unix) ReadMessage() (*messageMeta, error)

ReadMessage returns an incoming message after it has arrived

func (*Unix) StartServer

func (u *Unix) StartServer() error

StartServer blocks until a peer has connected

func (*Unix) WriteMessage

func (u *Unix) WriteMessage(metaBytes []byte, payload []byte) error

WriteMessage sends a message on the connection

type Websocket

type Websocket struct {
	ErrorChan chan (error)
	// contains filtered or unexported fields
}

Websocket is a transport for Twine

func (*Websocket) Close

func (w *Websocket) Close()

Close the websocket connection and shutdown read and write loops

func (*Websocket) ReadMessage

func (w *Websocket) ReadMessage() (*messageMeta, error)

ReadMessage reuturs the next message or an error This is a problem. Because if you don't call ReadMessage you just hang Should ebe replaced with GetMessageChannel

func (*Websocket) WriteMessage

func (w *Websocket) WriteMessage(meta []byte, payload []byte) error

WriteMessage implements twineConn's message sending

Directories

Path Synopsis
Package mock_twine is a generated GoMock package.
Package mock_twine is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL