noise

package
v0.0.0-...-0001d10 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrReadyUpgrade = errors.New("session is ready to upgrade")
)

Functions

func DeserializeFrame

func DeserializeFrame(r io.Reader, f *IncomingFrame) error

UnmarshalFrame deserializes a frame from a reader

func DeserializeResponseMessage

func DeserializeResponseMessage(r io.Reader, res *ResponseMessage) error

DeserializeResponseMessage unmarshals a response message from the enclave.

func MarshalFrame

func MarshalFrame(f *OutgoingFrame) ([]byte, error)

MarshalFrame serializes a frame into bytes so that it can be sent to the remote endpoint

func MarshalRequestMessage

func MarshalRequestMessage(m *OutgoingRequestMessage) ([]byte, error)

MarshalRequestMessage serializes an OutgoingRequestMessage to be sent to the remote endpoint

func SerializeBufferIntoFrame

func SerializeBufferIntoFrame(w io.Writer, buf *bytes.Buffer, sessionID []byte) error

SerializeBufferIntoFrame serializes the contents of a buffer into a RequestMessage

func SerializeFrame

func SerializeFrame(w io.Writer, f *OutgoingFrame) error

SerializeFrame serializes a frame into a writer

func SerializeIntoFrame

func SerializeIntoFrame(w io.Writer, r io.Reader, sessionID []byte) error

SerializeIntoFrame serializes a reader into a frame

func SerializeRequestMessage

func SerializeRequestMessage(w io.Writer, m *OutgoingRequestMessage) error

SerializeRequestMessage serializes an OutgoingRequestMessage into a writer

func UnmarshalCloseMessage

func UnmarshalCloseMessage(p []byte, res *CloseMessage) error

UnmarshalCloseMessage unmarshals a response message from the enclave.

func UnmarshalFrame

func UnmarshalFrame(p []byte, f *IncomingFrame) error

UnmarshalFrame deserializes a frame from bytes

Types

type Client

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

Client manages a fixed pool of connections and distributes work amongst them so that the caller does not need to worry about concurrency

func DialContext

func DialContext(ctx context.Context, props ClientProps) (*Client, error)

DialContext creates a new pool of connections

func (*Client) Request

func (p *Client) Request(ctx context.Context, req RequestPayload) (ResponsePayload, error)

Request issues a request to one of the connections in the pool and retrieves the response. The pool is concurrency safe.

type ClientFunc

type ClientFunc func(context.Context, io.Writer, io.Reader) error

ClientFunc allows functions to implement a client

func (ClientFunc) Request

func (fn ClientFunc) Request(ctx context.Context, w io.Writer, r io.Reader) error

Client implementation for ClientFunc

type ClientProps

type ClientProps struct {
	Conns        int
	Client       Requester
	SessionProps SessionProps
}

ClientProps sets up the connection pool

type CloseMessage

type CloseMessage struct{}

CloseMessage is the message type used when notifying the other end that the session will close

type Conn

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

Conn represents a noise connection to a remote endpoint. It abstracts handling of the session state. A connection is not concurrency safe, if that's a needed property looked into using a FixedConnPool. A Conn does not represent a real network connection, it's an abstraction which uses a client to create the illusion of a Conn, it's the Client implementation what defines the underlying model. A Conn allows mutliplexing of multiple sessions over the same networking connection.

func DialConnContext

func DialConnContext(ctx context.Context, client Requester, props *SessionProps) (*Conn, error)

DialConnContext creates a new connection and completes the handshake with the remote endpoint. If the handshake fails the Dial will also be considered failed

func (*Conn) Request

func (c *Conn) Request(ctx context.Context, req RequestPayload) (ResponsePayload, error)

Request issues a request in the reader and writes the received response back to the writer

type HandshakeCompletionStage

type HandshakeCompletionStage uint

HandshakeCompletionStage defines the completion stage for the session's handshake

const (
	// HandshakeInit the handshake still has to start or is already
	// in process
	HandshakeInit HandshakeCompletionStage = iota

	// Handshake has completed and the session can be upgraded to
	// handle application input/output
	HandshakeCompleted

	// HandshakeClosed the handshake has ended and the session
	// has been upgraded
	HandshakeClosed
)

type HandshakeHandler

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

HandshakeHandler is the handler the session uses to set up the handshake with the remote endpoint

func (*HandshakeHandler) CanUpgrade

func (s *HandshakeHandler) CanUpgrade() bool

CanUpgrade returns whether the Handler is in a HandshakeCompletionStage in which it can be upgraded to an established session

func (*HandshakeHandler) Read

func (s *HandshakeHandler) Read(w io.Writer, r io.Reader) (int, error)

Read reads remote input from an io.Reader, processes that input and writes the output (if any needs to be generated) to the writer

func (*HandshakeHandler) Upgrade

func (s *HandshakeHandler) Upgrade() (*TransportHandler, error)

Upgrade the HandshakeHandler to a TransportHandler so that the application can send/receive payloads

func (*HandshakeHandler) Write

func (s *HandshakeHandler) Write(w io.Writer, r io.Reader) (int, error)

Write reads local input for payloads that need to be sent from an io.Reader, processes the input and writes the output (if any needs to be generated) to the writer

type IncomingFrame

type IncomingFrame struct {
	Payload codec.Raw `codec:"payload"`
}

IncomingFrame is the frame used on top of the noise protocol to send messages and be able to multiplex them using the session ID as the identifier

type IncomingRequestMessage

type IncomingRequestMessage struct {
	Request codec.Raw `codec:"Request"`
}

IncomingRequestMessage is the message type used when sending requests to the remote endpoint

type IncomingResponseMessage

type IncomingResponseMessage struct {
	Response codec.Raw `codec:"Response"`
}

IncomingResponseMessage is the message type used when sending a response to a RequestMessage from the remote endpoint

type OutgoingFrame

type OutgoingFrame struct {
	SessionID []byte `codec:"session"`
	Payload   []byte `codec:"payload"`
}

OutgoingFrame is the frame used on top of the noise protocol to send messages and be able to multiplex them using the session ID as the identifier

type OutgoingRequestMessage

type OutgoingRequestMessage struct {
	Request RequestPayload `codec:"Request"`
}

OutgoingRequestMessage is the message type used when sending requests to the remote endpoint

type OutgoingResponseMessage

type OutgoingResponseMessage struct {
	Response []byte `codec:"Response"`
}

OutgoingResponseMessage is the message type used when sending a response to a RequestMessage from the remote endpoint

type RequestPayload

type RequestPayload struct {
	// Method is the method that the request will invoke
	Method string `codec:"method"`

	// Args are the arguments for invocation
	Args interface{} `codec:"args"`
}

RequestPayload is the representation of request used for serialization/deserialization

type Requester

type Requester interface {
	// Request abstracts a request into a reader which contains the
	// request, and a writer, where the response will be written
	Request(context.Context, io.Writer, io.Reader) error
}

Requester represents a channel between the local endpoint and the remote endpoint that a Conn uses to abstract the underlying transport

type ResponseBody

type ResponseBody struct {
	Body ResponsePayload `codec:"Body"`
}

ResponseBody is used to deserialize a received response

type ResponseMessage

type ResponseMessage struct {
	Response ResponsePayload
}

ResponseMessage defines the structure of a ResponseMessage. This struct should not be serialized directly, the helper (Serialize/Marshal)ResponseMessage should be used instead

type ResponsePayload

type ResponsePayload struct {
	// Success is the field that is set in case of a successful
	// response
	Success interface{} `codec:"Success"`

	// Error is the field that is set in case of a failed
	// response with information on the error's cause
	Error string `codec:"Error"`
}

ResponsePayload is the representation of an ekiden response used for serialization/deserialization

type Session

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

Session holds information on the state of a particular session, handling the protocol messages

func NewSession

func NewSession(props *SessionProps) (*Session, error)

NewSession creates a new noise session with the specific configuration. A session is not concurrency safe until the handshake has completed

func (*Session) CanUpgrade

func (s *Session) CanUpgrade() bool

CanUpgrade checks if the session has finished the handshake and can be upgraded to transport mode

func (*Session) ID

func (s *Session) ID() []byte

func (*Session) Read

func (s *Session) Read(w io.Writer, r io.Reader) (int, error)

Read bytes from the session

func (*Session) Upgrade

func (s *Session) Upgrade() (*Session, error)

Upgrades the session after the handler has been completed

func (*Session) Write

func (s *Session) Write(w io.Writer, r io.Reader) (int, error)

Write bytes to the session

type SessionProps

type SessionProps struct {
	// Initiator sets the role of this Session instance for the handshake. If
	// true, this Session initiates the handshake
	Initiator bool
}

SessionProps are the properties to configure the behaviour of a noise session

type TransportHandler

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

TransportHandler is the handler the session uses to send/receive data once the handshake has completed

func (*TransportHandler) Read

func (s *TransportHandler) Read(w io.Writer, r io.Reader) (int, error)

Read is the implementation of Read for rw.WrapReadWriter

func (*TransportHandler) Write

func (s *TransportHandler) Write(w io.Writer, r io.Reader) (int, error)

Write is the implementation of Write for rw.WrapReadWriter

Jump to

Keyboard shortcuts

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