Documentation
¶
Overview ¶
Copyright 2017 Mosaic Networks Ltd
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2017 Mosaic Networks Ltd ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2017 Mosaic Networks Ltd ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2017 Mosaic Networks Ltd ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2017 Mosaic Networks Ltd ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2017 Mosaic Networks Ltd ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- Variables
- func NewInmemAddr() string
- type ByPubKey
- type InmemTransport
- func (i *InmemTransport) Close() error
- func (i *InmemTransport) Connect(peer string, t Transport)
- func (i *InmemTransport) Consumer() <-chan RPC
- func (i *InmemTransport) Disconnect(peer string)
- func (i *InmemTransport) DisconnectAll()
- func (i *InmemTransport) LocalAddr() string
- func (i *InmemTransport) Sync(target string, args *SyncRequest, resp *SyncResponse) error
- type JSONPeers
- type LoopbackTransport
- type NetworkTransport
- type Peer
- type PeerStore
- type RPC
- type RPCResponse
- type StaticPeers
- type StreamLayer
- type SyncRequest
- type SyncResponse
- type TCPStreamLayer
- type Transport
- type WithPeers
Constants ¶
const ( // DefaultTimeoutScale is the default TimeoutScale in a NetworkTransport. DefaultTimeoutScale = 256 * 1024 // 256KB )
Variables ¶
var ( // ErrTransportShutdown is returned when operations on a transport are // invoked after it's been terminated. ErrTransportShutdown = errors.New("transport shutdown") // ErrPipelineShutdown is returned when the pipeline is closed. ErrPipelineShutdown = errors.New("append pipeline closed") )
Functions ¶
func NewInmemAddr ¶
func NewInmemAddr() string
NewInmemAddr returns a new in-memory addr with a randomly generate UUID as the ID.
Types ¶
type ByPubKey ¶
type ByPubKey []Peer
ByPubKey implements sort.Interface for []Peer based on the PubKeyHex field.
type InmemTransport ¶
InmemTransport Implements the Transport interface, to allow babble to be tested in-memory without going over a network.
func NewInmemTransport ¶
func NewInmemTransport(addr string) (string, *InmemTransport)
NewInmemTransport is used to initialize a new transport and generates a random local address if none is specified
func (*InmemTransport) Close ¶
func (i *InmemTransport) Close() error
Close is used to permanently disable the transport
func (*InmemTransport) Connect ¶
func (i *InmemTransport) Connect(peer string, t Transport)
Connect is used to connect this transport to another transport for a given peer name. This allows for local routing.
func (*InmemTransport) Consumer ¶
func (i *InmemTransport) Consumer() <-chan RPC
Consumer implements the Transport interface.
func (*InmemTransport) Disconnect ¶
func (i *InmemTransport) Disconnect(peer string)
Disconnect is used to remove the ability to route to a given peer.
func (*InmemTransport) DisconnectAll ¶
func (i *InmemTransport) DisconnectAll()
DisconnectAll is used to remove all routes to peers.
func (*InmemTransport) LocalAddr ¶
func (i *InmemTransport) LocalAddr() string
LocalAddr implements the Transport interface.
func (*InmemTransport) Sync ¶
func (i *InmemTransport) Sync(target string, args *SyncRequest, resp *SyncResponse) error
Sync implements the Transport interface.
type JSONPeers ¶
type JSONPeers struct {
// contains filtered or unexported fields
}
JSONPeers is used to provide peer persistence on disk in the form of a JSON file. This allows human operators to manipulate the file.
func NewJSONPeers ¶
NewJSONPeers creates a new JSONPeers store.
type LoopbackTransport ¶
type LoopbackTransport interface {
Transport // Embedded transport reference
WithPeers // Embedded peer management
}
LoopbackTransport is an interface that provides a loopback transport suitable for testing e.g. InmemTransport. It's there so we don't have to rewrite tests.
type NetworkTransport ¶
type NetworkTransport struct {
// contains filtered or unexported fields
}
NetworkTransport provides a network based transport that can be used to communicate with babble on remote machines. It requires an underlying stream layer to provide a stream abstraction, which can be simple TCP, TLS, etc.
This transport is very simple and lightweight. Each RPC request is framed by sending a byte that indicates the message type, followed by the gob encoded request.
The response is an error string followed by the response object, both are encoded using gob.
func NewNetworkTransport ¶
func NewNetworkTransport( stream StreamLayer, maxPool int, timeout time.Duration, logger *logrus.Logger, ) *NetworkTransport
NewNetworkTransport creates a new network transport with the given dialer and listener. The maxPool controls how many connections we will pool. The timeout is used to apply I/O deadlines.
func NewTCPTransport ¶
func NewTCPTransport( bindAddr string, advertise net.Addr, maxPool int, timeout time.Duration, logger *logrus.Logger, ) (*NetworkTransport, error)
NewTCPTransport returns a NetworkTransport that is built on top of a TCP streaming transport layer, with log output going to the supplied Logger
func (*NetworkTransport) Close ¶
func (n *NetworkTransport) Close() error
Close is used to stop the network transport.
func (*NetworkTransport) Consumer ¶
func (n *NetworkTransport) Consumer() <-chan RPC
Consumer implements the Transport interface.
func (*NetworkTransport) IsShutdown ¶
func (n *NetworkTransport) IsShutdown() bool
IsShutdown is used to check if the transport is shutdown.
func (*NetworkTransport) LocalAddr ¶
func (n *NetworkTransport) LocalAddr() string
LocalAddr implements the Transport interface.
func (*NetworkTransport) Sync ¶
func (n *NetworkTransport) Sync(target string, args *SyncRequest, resp *SyncResponse) error
Sync implements the Transport interface.
type Peer ¶
func ExcludePeer ¶
ExcludePeer is used to exclude a single peer from a list of peers.
func (*Peer) PubKeyBytes ¶
type PeerStore ¶
type PeerStore interface {
// Peers returns the list of known peers.
Peers() ([]Peer, error)
// SetPeers sets the list of known peers. This is invoked when a peer is
// added or removed.
SetPeers([]Peer) error
}
PeerStore provides an interface for persistent storage and retrieval of peers.
type RPC ¶
type RPC struct {
Command interface{}
Reader io.Reader
RespChan chan<- RPCResponse
}
RPC has a command, and provides a response mechanism.
type RPCResponse ¶
type RPCResponse struct {
Response interface{}
Error error
}
RPCResponse captures both a response and a potential error.
type StaticPeers ¶
type StaticPeers struct {
StaticPeers []Peer
// contains filtered or unexported fields
}
StaticPeers is used to provide a static list of peers.
func (*StaticPeers) Peers ¶
func (s *StaticPeers) Peers() ([]Peer, error)
Peers implements the PeerStore interface.
func (*StaticPeers) SetPeers ¶
func (s *StaticPeers) SetPeers(p []Peer) error
SetPeers implements the PeerStore interface.
type StreamLayer ¶
type StreamLayer interface {
net.Listener
// Dial is used to create a new outgoing connection
Dial(address string, timeout time.Duration) (net.Conn, error)
}
StreamLayer is used with the NetworkTransport to provide the low level stream abstraction.
type SyncRequest ¶
type SyncResponse ¶
type TCPStreamLayer ¶
type TCPStreamLayer struct {
// contains filtered or unexported fields
}
TCPStreamLayer implements StreamLayer interface for plain TCP.
func (*TCPStreamLayer) Accept ¶
func (t *TCPStreamLayer) Accept() (c net.Conn, err error)
Accept implements the net.Listener interface.
func (*TCPStreamLayer) Addr ¶
func (t *TCPStreamLayer) Addr() net.Addr
Addr implements the net.Listener interface.
func (*TCPStreamLayer) Close ¶
func (t *TCPStreamLayer) Close() (err error)
Close implements the net.Listener interface.
type Transport ¶
type Transport interface {
// Consumer returns a channel that can be used to
// consume and respond to RPC requests.
Consumer() <-chan RPC
// LocalAddr is used to return our local address to distinguish from our peers.
LocalAddr() string
// Sync sends the appropriate RPC to the target node.
Sync(target string, args *SyncRequest, resp *SyncResponse) error
// Close permanently closes a transport, stopping
// any associated goroutines and freeing other resources.
Close() error
}
Transport provides an interface for network transports to allow a node to communicate with other nodes.
type WithPeers ¶
type WithPeers interface {
Connect(peer string, t Transport) // Connect a peer
Disconnect(peer string) // Disconnect a given peer
DisconnectAll() // Disconnect all peers, possibly to reconnect them later
}
WithPeers is an interface that a transport may provide which allows for connection and disconnection. "Connect" is likely to be nil.