github.com/micro/go-micro/v2@v2.9.1/network/network.go (about)

     1  // Package network is for creating internetworks
     2  package network
     3  
     4  import (
     5  	"time"
     6  
     7  	"github.com/micro/go-micro/v2/client"
     8  	"github.com/micro/go-micro/v2/server"
     9  )
    10  
    11  var (
    12  	// DefaultName is default network name
    13  	DefaultName = "go.micro"
    14  	// DefaultAddress is default network address
    15  	DefaultAddress = ":0"
    16  	// ResolveTime defines time interval to periodically resolve network nodes
    17  	ResolveTime = 1 * time.Minute
    18  	// AnnounceTime defines time interval to periodically announce node neighbours
    19  	AnnounceTime = 1 * time.Second
    20  	// KeepAliveTime is the time in which we want to have sent a message to a peer
    21  	KeepAliveTime = 30 * time.Second
    22  	// SyncTime is the time a network node requests full sync from the network
    23  	SyncTime = 1 * time.Minute
    24  	// PruneTime defines time interval to periodically check nodes that need to be pruned
    25  	// due to their not announcing their presence within this time interval
    26  	PruneTime = 90 * time.Second
    27  )
    28  
    29  // Error is network node errors
    30  type Error interface {
    31  	// Count is current count of errors
    32  	Count() int
    33  	// Msg is last error message
    34  	Msg() string
    35  }
    36  
    37  // Status is node status
    38  type Status interface {
    39  	// Error reports error status
    40  	Error() Error
    41  }
    42  
    43  // Node is network node
    44  type Node interface {
    45  	// Id is node id
    46  	Id() string
    47  	// Address is node bind address
    48  	Address() string
    49  	// Peers returns node peers
    50  	Peers() []Node
    51  	// Network is the network node is in
    52  	Network() Network
    53  	// Status returns node status
    54  	Status() Status
    55  }
    56  
    57  // Network is micro network
    58  type Network interface {
    59  	// Node is network node
    60  	Node
    61  	// Initialise options
    62  	Init(...Option) error
    63  	// Options returns the network options
    64  	Options() Options
    65  	// Name of the network
    66  	Name() string
    67  	// Connect starts the resolver and tunnel server
    68  	Connect() error
    69  	// Close stops the tunnel and resolving
    70  	Close() error
    71  	// Client is micro client
    72  	Client() client.Client
    73  	// Server is micro server
    74  	Server() server.Server
    75  }
    76  
    77  // NewNetwork returns a new network interface
    78  func NewNetwork(opts ...Option) Network {
    79  	return newNetwork(opts...)
    80  }