quibit

package module
v0.0.0-...-aa5af93 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2014 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package quibit provides basic Peer-To-Peer asynchronous network functionality and peer management.

Index

Constants

View Source
const (
	BROADCAST = iota
	REQUEST   = iota
	REPLY     = iota
)

Message Types:

Broadcast goes to all connected peers except for the Peer specified in the Frame.

Request and Reply go to the Peer specified in the Frame.

View Source
const (
	MAGIC = 6667787
)

Variables

This section is empty.

Functions

func Cleanup

func Cleanup()

Cleanup the Quibit Service

End the mux and server routines, and Disconnect from all peers.

func Initialize

func Initialize(log chan string, recvChan, sendChan chan Frame, peerChan chan Peer, port uint16) error

Initialize the Quibit Service

Frames from the network will be sent to recvChan, and includes the sending peer

Frames for the network should be sent to sendChan, and include the receiving peer

New Peers for connecting should be sent to peerChan.

A local server will be started on the port specified by "port"

If an error is returned, than neither the server or mux has been started.

func KillPeer

func KillPeer(p string)

KillPeer Force Disconnects from a Peer

All incoming data is dropped and the peer is removed from the Peer List

func Status

func Status() int

Status returns the Current Connection Status

Returns 0 on disconnected. Returns 1 on Client Connection (Outgoing Connections Only). Returns 2 On Full Connection (Incoming and Outgoing Connections).

Types

type Frame

type Frame struct {
	Peer    string // Peer who sent or will receive this frame
	Header  Header // Header associated with frame
	Payload []byte // Serialize frame payload
}

func (*Frame) Configure

func (f *Frame) Configure(data []byte, command, t uint8)

Configure Frame f with a proper header for payload "data" interpreted as "command"

type Header struct {
	Magic    uint32   // Known magic number
	Command  uint8    // How to interpret payload
	Type     uint8    // How to interpret payload
	Checksum [48]byte // SHA-384 Checksum of Payload
	Length   uint32   // Length of Payload
}

Used as a fixed-length description of a frame

func (*Header) Configure

func (h *Header) Configure(data []byte)

Configure a new header given the frame payload

func (*Header) FromBytes

func (h *Header) FromBytes(b []byte) error

Unserialize header from the wire

func (*Header) ToBytes

func (h *Header) ToBytes() ([]byte, error)

Serialize Header for sending over the wire

type Peer

type Peer struct {
	IP   net.IP // Standard 16-byte IP Address
	Port uint16 // Standard 2-byte TCP Port
	// contains filtered or unexported fields
}

func GetPeer

func GetPeer(p string) *Peer

Get Peer associated with the given <IP>:<Host> string

<nil> Signifies a disconnected or unknown peer.

func (*Peer) Disconnect

func (p *Peer) Disconnect()

Forces Disconnect from Peer and closes all incoming connections.

func (*Peer) IsConnected

func (p *Peer) IsConnected() bool

Returns the connection status of Peer

func (*Peer) String

func (p *Peer) String() string

String returns the <IP>:<Host> Identifier of Peer

type QuibitError

type QuibitError int

Error type for Quibit-Specific Errors

func (QuibitError) Error

func (e QuibitError) Error() string

Jump to

Keyboard shortcuts

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