hub

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Conn is a wrapper of the origin network connection. It resolves the handshake information from the first version message including magic number, PID, network address etc.

Hub is a network hub to provide different services through one network address.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until either UseLogger or SetLogWriter are called.

func PIDTo16

func PIDTo16(pid [33]byte) [16]byte

PIDTo16 converts a PID to [16]byte with the last 16 bytes of PID.

func UseLogger

func UseLogger(logger elalog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using elalog.

Types

type Conn

type Conn struct {
	net.Conn // The origin network connection.
	// contains filtered or unexported fields
}

Conn is a wrapper of the origin network connection.

func WrapConn

func WrapConn(c net.Conn) (conn *Conn, err error)

WrapConn warps the origin network connection and returns a hub connection with the handshake information resolved from version message.

func (*Conn) Magic

func (c *Conn) Magic() uint32

Magic returns the magic number resolved from message header.

func (*Conn) NetAddr

func (c *Conn) NetAddr() net.Addr

NetAddr returns the network address resolve from the origin connection and the version message.

func (*Conn) PID

func (c *Conn) PID() [33]byte

PID returns the PID resolved from the version message. It represents who is connecting.

func (*Conn) Read

func (c *Conn) Read(b []byte) (n int, err error)

Read warps the origin Read method without knowing we have intercepted the version message.

func (*Conn) Target

func (c *Conn) Target() [16]byte

Target returns the Target PID resolved from the version message. It used when a service behind the hub want to connect to another service, representing who the service is going to connect.

type Hub

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

func New

func New(magic uint32, pid [33]byte, admgr *addrmgr.AddrManager) *Hub

New creates a new Hub instance with the main network magic, arbiter PID and DPOS network AddrManager.

func (*Hub) Intercept

func (h *Hub) Intercept(conn net.Conn) net.Conn

Intercept intercepts the accepted connection and distribute the connection to the right service, returns nil if the connection has been intercepted.

Jump to

Keyboard shortcuts

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