net

package
v0.0.0-...-457749f Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2020 License: AGPL-3.0 Imports: 26 Imported by: 0

README

go-dvote net module

Wraps multiple messaging/communication protocols in a common interface intended to facilitate flexible stream processing

Generic Interface

The primary interface presented by the net module is the Transport interface. It represents a bidrectional connection to a particular p2p messaging channel, or websocket connection pool.

The various underlying protocols are identified by a TransportID:

transportType := net.TransportTypeFromString("PSS")

An active default transport is initalized by a call to the module's public InitDefault method:

PSSTransport, err :=  net.InitDefault(transportType)

Transports expect to relay what they recieve to a Message channel, and to have an error channel for signaling:

listenerOutput := make(chan types.Message, 10)
listenerErrors := make(chan error)

To concurrently ingest a stream:

go transport.Listen(listenerOutput, listenerErrors)

The Transport Send method expect a slice of bytes, and a channel to which it can send any errors:

sendErrors := make(chan error)
exampleMessage := []byte{'d', 'v', 'o', 't', 'e'}
transport.Send(exampleMessage, sendErrors)

Supported protocols

Currently supported are PSS and PubSub. Websocket support is planned in the near future.

Pubsub

The relevant Connection specifier field for PubSub is the Topic:

exampleConnection := new(types.Connection)
exampleConnection.Topic = "exampleTopic"
exampleTransport, err := net.Init(transportType, exampleConnection)
//use as above
Websockets

Work in progress

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HttpContext

type HttpContext struct {
	Writer  http.ResponseWriter
	Request *http.Request
	// contains filtered or unexported fields
}

func (*HttpContext) ConnectionType

func (h *HttpContext) ConnectionType() string

func (*HttpContext) Send

func (h *HttpContext) Send(msg types.Message)

type HttpHandler

type HttpHandler struct {
	Proxy *Proxy // proxy where the ws will be associated
	// contains filtered or unexported fields
}

func (*HttpHandler) AddNamespace

func (h *HttpHandler) AddNamespace(namespace string)

AddNamespace adds a new namespace to the transport

func (*HttpHandler) AddPeer

func (h *HttpHandler) AddPeer(peer string) error

func (*HttpHandler) AddProxyHandler

func (h *HttpHandler) AddProxyHandler(path string)

AddProxyHandler adds the current websocket handler into the Proxy

func (*HttpHandler) Address

func (h *HttpHandler) Address() string

func (*HttpHandler) ConnectionType

func (h *HttpHandler) ConnectionType() string

func (*HttpHandler) Init

func (h *HttpHandler) Init(c *types.Connection) error

func (*HttpHandler) Listen

func (h *HttpHandler) Listen(receiver chan<- types.Message)

func (*HttpHandler) Send

func (h *HttpHandler) Send(msg types.Message)

func (*HttpHandler) SendUnicast

func (h *HttpHandler) SendUnicast(address string, msg types.Message)

func (*HttpHandler) SetBootnodes

func (h *HttpHandler) SetBootnodes(bootnodes []string)

func (*HttpHandler) SetProxy

func (h *HttpHandler) SetProxy(p *Proxy)

func (*HttpHandler) String

func (h *HttpHandler) String() string

type HttpWsHandler

type HttpWsHandler struct {
	Proxy      *Proxy            // proxy where the ws will be associated
	Connection *types.Connection // the ws connection
	// contains filtered or unexported fields
}

HttpWsHandler is a Mixed handler websockets/http

func (*HttpWsHandler) AddNamespace

func (h *HttpWsHandler) AddNamespace(namespace string)

AddNamespace adds a new namespace to the transport

func (*HttpWsHandler) AddPeer

func (h *HttpWsHandler) AddPeer(peer string) error

func (*HttpWsHandler) AddProxyHandler

func (h *HttpWsHandler) AddProxyHandler(path string)

AddProxyHandler adds the current websocket handler into the Proxy

func (*HttpWsHandler) Address

func (h *HttpWsHandler) Address() string

func (*HttpWsHandler) ConnectionType

func (h *HttpWsHandler) ConnectionType() string

func (*HttpWsHandler) Init

func (h *HttpWsHandler) Init(c *types.Connection) error

func (*HttpWsHandler) Listen

func (h *HttpWsHandler) Listen(receiver chan<- types.Message)

func (*HttpWsHandler) Send

func (h *HttpWsHandler) Send(msg types.Message)

func (*HttpWsHandler) SendUnicast

func (h *HttpWsHandler) SendUnicast(address string, msg types.Message)

func (*HttpWsHandler) SetBootnodes

func (h *HttpWsHandler) SetBootnodes(bootnodes []string)

func (*HttpWsHandler) SetProxy

func (h *HttpWsHandler) SetProxy(p *Proxy)

func (*HttpWsHandler) String

func (h *HttpWsHandler) String() string

type Proxy

type Proxy struct {
	Conn   *types.Connection
	Server *chi.Mux
	Addr   net.Addr
}

Proxy represents a proxy

func NewProxy

func NewProxy() *Proxy

NewProxy creates a new proxy instance

func (*Proxy) AddEndpoint

func (p *Proxy) AddEndpoint(url string) func(writer http.ResponseWriter, reader *http.Request)

AddEndpoint adds an endpoint representing the url where the request will be handled

func (*Proxy) AddHandler

func (p *Proxy) AddHandler(path string, handler http.HandlerFunc)

AddHandler adds a HTTP handler in the proxy

func (*Proxy) AddMixedHandler

func (p *Proxy) AddMixedHandler(path string, HTTPhandler http.HandlerFunc, WShandler ProxyWsHandler)

AddMixedHandler adds a mixed (websockets and HTTP) handler in the proxy

func (*Proxy) AddWsHTTPBridge

func (p *Proxy) AddWsHTTPBridge(url string) ProxyWsHandler

AddWsHTTPBridge adds a WS endpoint to interact with the underlying web3

func (*Proxy) AddWsHandler

func (p *Proxy) AddWsHandler(path string, handler ProxyWsHandler)

AddWsHandler adds a websocket handler in the proxy

func (*Proxy) AddWsWsBridge

func (p *Proxy) AddWsWsBridge(url string) ProxyWsHandler

AddWsWsBridge adds a WS endpoint to interact with the underlying web3

func (*Proxy) GenerateSSLCertificate

func (p *Proxy) GenerateSSLCertificate() (*http.Server, *autocert.Manager)

GenerateSSLCertificate generates a SSL certificated for the proxy

func (*Proxy) Init

func (p *Proxy) Init() error

Init checks if SSL is activated or not and runs a http server consequently

When it returns, the server is ready. The returned address is useful if the port was left as 0, to retrieve the randomly allocated port.

func (*Proxy) ProxyIPC

func (p *Proxy) ProxyIPC(path string) http.HandlerFunc

type ProxyWsHandler

type ProxyWsHandler func(c *websocket.Conn)

ProxyWsHandler function signature required to add a handler in the net/http Server

type SubPubHandle

type SubPubHandle struct {
	Conn      *types.Connection
	SubPub    *subpub.SubPub
	BootNodes []string
}

func (*SubPubHandle) AddNamespace

func (s *SubPubHandle) AddNamespace(namespace string)

func (*SubPubHandle) AddPeer

func (s *SubPubHandle) AddPeer(peer string) error

func (*SubPubHandle) Address

func (s *SubPubHandle) Address() string

func (*SubPubHandle) ConnectionType

func (s *SubPubHandle) ConnectionType() string

func (*SubPubHandle) Init

func (p *SubPubHandle) Init(c *types.Connection) error

func (*SubPubHandle) Listen

func (s *SubPubHandle) Listen(reciever chan<- types.Message)

func (*SubPubHandle) Send

func (s *SubPubHandle) Send(msg types.Message)

func (*SubPubHandle) SendUnicast

func (s *SubPubHandle) SendUnicast(address string, msg types.Message)

func (*SubPubHandle) SetBootnodes

func (s *SubPubHandle) SetBootnodes(bootnodes []string)

func (*SubPubHandle) String

func (s *SubPubHandle) String() string

type Transport

type Transport interface {
	ConnectionType() string
	Listen(reciever chan<- types.Message)
	Send(msg types.Message)
	AddNamespace(namespace string)
	SendUnicast(address string, msg types.Message)
	Init(c *types.Connection) error
	Address() string
	SetBootnodes(bootnodes []string)
	AddPeer(peer string) error
	String() string
}

func Init

func InitDefault

func InitDefault(t TransportID) (Transport, error)

type TransportID

type TransportID int
const (
	SubPub TransportID = iota + 1
)

func TransportIDFromString

func TransportIDFromString(i string) TransportID

type WebsocketContext

type WebsocketContext struct {
	Conn *websocket.Conn
}

func (WebsocketContext) ConnectionType

func (c WebsocketContext) ConnectionType() string

func (*WebsocketContext) Send

func (c *WebsocketContext) Send(msg types.Message)

type WebsocketHandle

type WebsocketHandle struct {
	Connection *types.Connection // the ws connection
	WsProxy    *Proxy            // proxy where the ws will be associated
	// contains filtered or unexported fields
}

WebsocketHandle handles the websockets connection on the go-dvote proxy

func (*WebsocketHandle) AddNamespace

func (w *WebsocketHandle) AddNamespace(namespace string)

Listen will listen the websockets handler and write the received data into the channel

func (*WebsocketHandle) AddPeer

func (w *WebsocketHandle) AddPeer(peer string) error

func (*WebsocketHandle) AddProxyHandler

func (w *WebsocketHandle) AddProxyHandler(path string)

AddProxyHandler adds the current websocket handler into the Proxy

func (*WebsocketHandle) Address

func (w *WebsocketHandle) Address() string

func (*WebsocketHandle) ConnectionType

func (w *WebsocketHandle) ConnectionType() string

ConnectionType returns a string identifying the transport connection type

func (*WebsocketHandle) Init

func (w *WebsocketHandle) Init(c *types.Connection) error

Init initializes the websockets handler and the internal channel to communicate with other go-dvote components

func (*WebsocketHandle) Listen

func (w *WebsocketHandle) Listen(receiver chan<- types.Message)

Listen will listen the websockets handler and write the received data into the channel

func (*WebsocketHandle) Send

func (w *WebsocketHandle) Send(msg types.Message)

Send sends the response given a message

func (*WebsocketHandle) SendUnicast

func (w *WebsocketHandle) SendUnicast(address string, msg types.Message)

func (*WebsocketHandle) SetBootnodes

func (w *WebsocketHandle) SetBootnodes(bootnodes []string)

func (*WebsocketHandle) SetProxy

func (w *WebsocketHandle) SetProxy(p *Proxy)

SetProxy sets the proxy for the ws

func (*WebsocketHandle) String

func (w *WebsocketHandle) String() string

Jump to

Keyboard shortcuts

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