nymsocketmanager

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2023 License: GPL-3.0 Imports: 8 Imported by: 0

README

NymSocketManager

Go Reference

This Go module handles the connection to the Nym Mixnet let you focus on the rest of your application.

Note that this module needs a running nym-client to connect to the mixnet! It can be downloaded here or built according the instructions here. Instructions for initiating and running a nym-client can be found here.

Installation

NymSocketManager is available using the standard go get command.

Install it by running:

go get -u github.com/notrustverify/nymsocketmanager

Usage

The module can be imported as following:

import NymSocketManager "github.com/notrustverify/nymsocketmanager"

You can thenow instantiate the NymSocketManager or the SocketManager.

Example

Examples on how to use both NymSocketManager and SocketManager can be found in the examples folder.
You can also check our Nostr-Nym proxy in Go: NostrNym.

Future improvements

The following could be improved regarding this module:

  • Improve type documentation
  • Write more tests
  • Use the WS library for websocket connections. This module currently uses the Gorilla Websocket library, which is unmaintained at the current time of writing (05.2023).

License

This code is released under the GPLv3+ license.

Documentation

Index

Constants

View Source
const ComponentField = "component"
View Source
const NymErrorType = "error"
View Source
const NymReceivedType = "received"
View Source
const NymReplyType = "reply"
View Source
const NymSelfAddressReplyType = "selfAddress"
View Source
const NymSelfAddressType = "selfAddress"
View Source
const NymSendAnonymousType = "sendAnonymous"
View Source
const NymSendType = "send"

Variables

This section is empty.

Functions

This section is empty.

Types

type NymError

type NymError struct {
	NymMessageCommon

	Message string `json:"message"`
}

func (NymError) Name

func (NymError) Name() string

func (NymError) NewEmpty

func (NymError) NewEmpty() NymMessage

func (NymError) String

func (n NymError) String() string

type NymMessage

type NymMessage interface {
	NewEmpty() NymMessage
	Name() string // Type of message
	String() string
}

Message defines the type of message that can be exchanged

func NewNymReceived added in v0.0.2

func NewNymReceived(message string, senderTag string) NymMessage

func NewNymReply

func NewNymReply(senderTag string, message string) NymMessage

func NewNymSend added in v0.0.2

func NewNymSend(message string, recipient string) NymMessage

func NewNymSendAnonymous added in v0.0.2

func NewNymSendAnonymous(message string, recipient string, nbReplySurbs uint) NymMessage

func NewSelfAddressReply added in v0.0.2

func NewSelfAddressReply(address string) NymMessage

func NewSelfAddressRequest

func NewSelfAddressRequest() NymMessage

type NymMessageCommon

type NymMessageCommon struct {
	Type string `json:"type"`
}

type NymReceived

type NymReceived struct {
	NymMessageCommon

	Message   string `json:"message"`
	SenderTag string `json:"senderTag"`
}

func (NymReceived) Name

func (NymReceived) Name() string

func (NymReceived) NewEmpty

func (NymReceived) NewEmpty() NymMessage

func (NymReceived) String

func (n NymReceived) String() string

type NymReply

type NymReply struct {
	NymMessageCommon

	Message   string `json:"message"`
	SenderTag string `json:"senderTag"`
}

func (NymReply) Name

func (NymReply) Name() string

func (NymReply) NewEmpty

func (n NymReply) NewEmpty() NymMessage

func (NymReply) String

func (n NymReply) String() string

type NymSelfAddressReply

type NymSelfAddressReply struct {
	NymMessageCommon

	Address string `json:"address"`
}

func (NymSelfAddressReply) Name

func (NymSelfAddressReply) Name() string

func (NymSelfAddressReply) NewEmpty

func (s NymSelfAddressReply) NewEmpty() NymMessage

func (NymSelfAddressReply) String

func (n NymSelfAddressReply) String() string

type NymSelfAddressRequest

type NymSelfAddressRequest struct {
	NymMessageCommon
}

func (NymSelfAddressRequest) Name

func (NymSelfAddressRequest) NewEmpty

func (NymSelfAddressRequest) NewEmpty() NymMessage

func (NymSelfAddressRequest) String

func (NymSelfAddressRequest) String() string

type NymSend added in v0.0.2

type NymSend struct {
	NymMessageCommon

	Message   string `json:"message"`
	Recipient string `json:"recipient"`
}

func (NymSend) Name added in v0.0.2

func (NymSend) Name() string

func (NymSend) NewEmpty added in v0.0.2

func (NymSend) NewEmpty() NymMessage

func (NymSend) String added in v0.0.2

func (n NymSend) String() string

type NymSendAnonymous added in v0.0.2

type NymSendAnonymous struct {
	NymMessageCommon

	Message    string `json:"message"`
	Recipient  string `json:"recipient"`
	ReplySurbs uint   `json:"replySurbs"`
}

func (NymSendAnonymous) Name added in v0.0.2

func (NymSendAnonymous) Name() string

func (NymSendAnonymous) NewEmpty added in v0.0.2

func (NymSendAnonymous) NewEmpty() NymMessage

func (NymSendAnonymous) String added in v0.0.2

func (n NymSendAnonymous) String() string

type NymSocketManager

type NymSocketManager struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewNymSocketManager

func NewNymSocketManager(connectionURI string, messageHandler func(NymReceived, func(NymMessage) error), parentLogger *zerolog.Logger) (*NymSocketManager, error)

func (*NymSocketManager) GetConnectedGateway added in v0.0.2

func (n *NymSocketManager) GetConnectedGateway() string

func (*NymSocketManager) GetNymClientId

func (n *NymSocketManager) GetNymClientId() string

func (*NymSocketManager) IsRunning

func (n *NymSocketManager) IsRunning() bool

func (*NymSocketManager) Send

func (n *NymSocketManager) Send(msg NymMessage) error

Send a message to the underlying connection

func (*NymSocketManager) Start

func (n *NymSocketManager) Start() (chan struct{}, error)

func (*NymSocketManager) Stop

func (n *NymSocketManager) Stop()

type SocketListener

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

func NewSocketListener

func NewSocketListener(socket *websocket.Conn, messageHandler func([]byte), toCallWhenClosed func(), parentLogger *zerolog.Logger) (*SocketListener, chan struct{}, error)

func (*SocketListener) Listen

func (s *SocketListener) Listen()

type SocketManager

type SocketManager struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewSocketManager

func NewSocketManager(connectionURI string, messageHandler func([]byte, func([]byte) error), parentLogger *zerolog.Logger) (*SocketManager, error)

func (*SocketManager) IsRunning

func (s *SocketManager) IsRunning() bool

func (*SocketManager) Send

func (s *SocketManager) Send(message []byte) error

func (*SocketManager) Start

func (s *SocketManager) Start() (chan struct{}, error)

func (*SocketManager) Stop

func (s *SocketManager) Stop()

Jump to

Keyboard shortcuts

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