connection

package
v0.0.0-...-ddc3094 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2015 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MainNetStartString = []byte{0xf9, 0xbe, 0xb4, 0xd9}
View Source
var RegTestStartString = []byte{0xfa, 0xbf, 0xb5, 0xda}
View Source
var TestNetStartString = []byte{0x0b, 0x11, 0x09, 0x07}

TODO add support for test nets.

Functions

func ParseOneMessage

func ParseOneMessage(input io.Reader, magic []byte) (string, []byte, error)

func SeekToNextMessage

func SeekToNextMessage(input io.Reader, magic []byte) error

Consume input until a start string is found. The start string is also consumed.

func Send

func Send(c Conn, m Message) error

Send will add a message to the connection's WriteChannel, or fail if the channel's buffer is full.

Types

type Config

type Config struct {
	Version          int32
	MinRemoteVersion int32
	Services         uint64
	UserAgent        string
	StartHeight      int32
	Relay            bool
}

type Conn

type Conn interface {
	// Name/address of the endpoint we're connected to.
	Endpoint() string

	// Write to this channel to send messages on the connection.
	WriteChannel() chan<- Message

	// Connection failed to set up and should not be used or closed. Only
	// initial errors will set this, later errors will come through
	// the channel provided to Run().
	Error() error

	// Start the operation of a connected connection. Errors and received
	// messages will be passed on the provided channel. The caller can
	// safely close the channel after Close() returns.
	Run(chan<- Message)

	// Close connection. Blocks until it's done, specifically it's safe to
	// close the channel provided to Run() when this call returns. Only
	// call when connected, ie. when Error() == nil.
	Close()

	MostRecentActivity() time.Time
}

func Connect

func Connect(endpoint string, config Config) Conn

Connect connectes to the given endpoint and returns a Connection when the connection has been established (or failed -- check Error()). If the connection was successful, operations may be started by calling Run(), and must be stopped with Close().

type ConnImpl

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

func (*ConnImpl) Close

func (c *ConnImpl) Close()

func (*ConnImpl) Endpoint

func (c *ConnImpl) Endpoint() string

func (*ConnImpl) Error

func (c *ConnImpl) Error() error

func (*ConnImpl) MostRecentActivity

func (c *ConnImpl) MostRecentActivity() time.Time

func (*ConnImpl) Run

func (c *ConnImpl) Run(readCh chan<- Message)

startMainThread starts the main loop than handles incoming and outgoing messages. Incoming messages are forwarded to the read channel provided.

func (*ConnImpl) WriteChannel

func (c *ConnImpl) WriteChannel() chan<- Message

type Message

type Message struct {
	Endpoint string
	Type     string
	Data     []byte
	// contains filtered or unexported fields
}

func ErrorMessage

func ErrorMessage(name string, err error) Message

func NewMessage

func NewMessage(endpoint, typ string, data []byte) Message

func (Message) Error

func (m Message) Error() error

Jump to

Keyboard shortcuts

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