client

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2022 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalCredential

func MarshalCredential(myKey wgtypes.Key, remoteKey wgtypes.Key, credential *Credential, t proto.Body_Type) (*proto.Message, error)

MarshalCredential marsharl a Credential instance and returns a Message object

Types

type Client

type Client interface {
	io.Closer
	StreamConnected() bool
	GetStatus() Status
	Receive(msgHandler func(msg *proto.Message) error) error
	Ready() bool
	WaitStreamConnected()
	SendToStream(msg *proto.EncryptedMessage) error
	Send(msg *proto.Message) error
}

type Credential

type Credential struct {
	UFrag string
	Pwd   string
}

Credential is an instance of a GrpcClient's Credential

func UnMarshalCredential

func UnMarshalCredential(msg *proto.Message) (*Credential, error)

UnMarshalCredential parses the credentials from the message and returns a Credential instance

type GrpcClient added in v0.3.4

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

GrpcClient Wraps the Signal Exchange Service gRpc client

func NewClient

func NewClient(ctx context.Context, addr string, key wgtypes.Key, tlsEnabled bool) (*GrpcClient, error)

NewClient creates a new Signal client

func (*GrpcClient) Close added in v0.3.4

func (c *GrpcClient) Close() error

Close Closes underlying connections to the Signal Exchange

func (*GrpcClient) GetStatus added in v0.3.4

func (c *GrpcClient) GetStatus() Status

func (*GrpcClient) Ready added in v0.3.4

func (c *GrpcClient) Ready() bool

Ready indicates whether the client is okay and Ready to be used for now it just checks whether gRPC connection to the service is in state Ready

func (*GrpcClient) Receive added in v0.3.4

func (c *GrpcClient) Receive(msgHandler func(msg *proto.Message) error) error

Receive Connects to the Signal Exchange message stream and starts receiving messages. The messages will be handled by msgHandler function provided. This function is blocking and reconnects to the Signal Exchange if errors occur (e.g. Exchange restart) The connection retry logic will try to reconnect for 30 min and if wasn't successful will propagate the error to the function caller.

func (*GrpcClient) Send added in v0.3.4

func (c *GrpcClient) Send(msg *proto.Message) error

Send sends a message to the remote Peer through the Signal Exchange.

func (*GrpcClient) SendToStream added in v0.3.4

func (c *GrpcClient) SendToStream(msg *proto.EncryptedMessage) error

SendToStream sends a message to the remote Peer through the Signal Exchange using established stream connection to the Signal Server The GrpcClient.Receive method must be called before sending messages to establish initial connection to the Signal Exchange GrpcClient.connWg can be used to wait

func (*GrpcClient) StreamConnected added in v0.3.4

func (c *GrpcClient) StreamConnected() bool

func (*GrpcClient) WaitStreamConnected added in v0.3.4

func (c *GrpcClient) WaitStreamConnected()

WaitStreamConnected waits until the client is connected to the Signal stream

type MockClient added in v0.3.4

type MockClient struct {
	CloseFunc               func() error
	GetStatusFunc           func() Status
	StreamConnectedFunc     func() bool
	ReadyFunc               func() bool
	WaitStreamConnectedFunc func()
	ReceiveFunc             func(msgHandler func(msg *proto.Message) error) error
	SendToStreamFunc        func(msg *proto.EncryptedMessage) error
	SendFunc                func(msg *proto.Message) error
}

func (*MockClient) Close added in v0.3.4

func (sm *MockClient) Close() error

func (*MockClient) GetStatus added in v0.3.4

func (sm *MockClient) GetStatus() Status

func (*MockClient) Ready added in v0.3.4

func (sm *MockClient) Ready() bool

func (*MockClient) Receive added in v0.3.4

func (sm *MockClient) Receive(msgHandler func(msg *proto.Message) error) error

func (*MockClient) Send added in v0.3.4

func (sm *MockClient) Send(msg *proto.Message) error

func (*MockClient) SendToStream added in v0.3.4

func (sm *MockClient) SendToStream(msg *proto.EncryptedMessage) error

func (*MockClient) StreamConnected added in v0.3.4

func (sm *MockClient) StreamConnected() bool

func (*MockClient) WaitStreamConnected added in v0.3.4

func (sm *MockClient) WaitStreamConnected()

type Status

type Status string

Status is the status of the client

const StreamConnected Status = "Connected"
const StreamDisconnected Status = "Disconnected"

Jump to

Keyboard shortcuts

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