-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
92dc0a6
commit 4e4ed7f
Showing
4 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package gossip | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/andydunstall/pico/pkg/log" | ||
"github.com/andydunstall/pico/server/netmap" | ||
) | ||
|
||
// Gossip is responsible for maintaining the nodes local NetworkMap and | ||
// propagating the state of the local node to the rest of the cluster. | ||
type Gossip struct { | ||
netmap *netmap.NetworkMap | ||
logger *log.Logger | ||
} | ||
|
||
// NewGossip initializes gossip to maintain the given network map. | ||
func NewGossip(netmap *netmap.NetworkMap, logger *log.Logger) *Gossip { | ||
return &Gossip{ | ||
netmap: netmap, | ||
logger: logger.WithSubsystem("gossip"), | ||
} | ||
} | ||
|
||
// Run gossips with the other nodes in the cluster until cancelled. | ||
func (g *Gossip) Run(_ context.Context) error { | ||
g.logger.Info("starting gossip") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package netmap | ||
|
||
// NetworkMap represents the known state of the cluster as seen by the local | ||
// node. | ||
// | ||
// This map is eventually consistent. The state is propagated among the nodes | ||
// in the cluster using gossip. | ||
type NetworkMap struct { | ||
} | ||
|
||
func NewNetworkMap() *NetworkMap { | ||
return &NetworkMap{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package netmap | ||
|
||
// Node represents the known state about a node in the cluster. | ||
type Node struct { | ||
// ID is a unique identifier for the node in the cluster. | ||
ID string | ||
|
||
// HTTPAddr is the advertised HTTP address | ||
HTTPAddr string | ||
|
||
// GossipAddr is the advertised gossip address. | ||
GossipAddr string | ||
|
||
// Endpoints contains the active endpoints on the node. This maps the | ||
// active endpoint ID to the number of listeners for that endpoint. | ||
Endpoints map[string]int | ||
} |