-
Notifications
You must be signed in to change notification settings - Fork 106
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
Showing
13 changed files
with
218 additions
and
76 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
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
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,82 @@ | ||
package node | ||
|
||
import ( | ||
"encoding/json" | ||
"io/ioutil" | ||
"sync" | ||
|
||
"github.com/pokt-network/pocket-core/types" | ||
) | ||
|
||
type List types.List | ||
|
||
var ( | ||
o sync.Once | ||
pl *List | ||
) | ||
|
||
// "GetPeerList" returns the global map of nodes. | ||
func GetPeerList() *List { | ||
o.Do(func() { | ||
pl = (*List)(types.NewList()) | ||
}) | ||
return pl | ||
} | ||
|
||
// "Add" adds a peer object to the global map. | ||
func (pl *List) Add(node Node) { | ||
(*types.List)(pl).Add(node.GID, node) | ||
} | ||
|
||
// "Remove" removes a peer object from the global map. | ||
func (pl *List) Remove(node Node) { | ||
(*types.List)(pl).Remove(node.GID) | ||
} | ||
|
||
// "Contains" returns true if node is within peerlist. | ||
func (pl *List) Contains(gid string) bool { | ||
return (*types.List)(pl).Contains(gid) | ||
} | ||
|
||
// "Count" returns the count of peers within the map. | ||
func (pl *List) Count() int { | ||
return (*types.List)(pl).Count() | ||
} | ||
|
||
// "Print" prints the peerlist to the CLI | ||
func (pl *List) Print() { | ||
(*types.List)(pl).Print() | ||
} | ||
|
||
// "ManualPeersFile" adds Map from a peers.json to the peerlist | ||
func ManualPeersFile(filepath string) error { | ||
file, err := ioutil.ReadFile(filepath) | ||
if err != nil { | ||
return err | ||
} | ||
return manualPeersJSON(file) | ||
} | ||
|
||
// "manualPeersJSON" adds Map from a json []byte to the peerlist | ||
func manualPeersJSON(b []byte) error { | ||
var nSlice []Node | ||
if err := json.Unmarshal(b, &nSlice); err != nil { | ||
return err | ||
} | ||
for _, n := range nSlice { | ||
pList := GetPeerList() | ||
pList.Add(n) | ||
} | ||
return nil | ||
} | ||
|
||
// DISCLAIMER: the code below is for pocket core mvp centralized dispatcher | ||
// may remove for production | ||
|
||
func (pl *List) CopyToDP() { | ||
pl.Mux.Lock() | ||
defer pl.Mux.Unlock() | ||
for _, peer := range pl.M { | ||
GetDispatchPeers().Add(peer.(Node)) | ||
} | ||
} |
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
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
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,21 @@ | ||
package session | ||
|
||
import "github.com/pokt-network/pocket-core/types" | ||
|
||
type PeerList types.List | ||
|
||
func NewPeerList() PeerList { | ||
return *(*PeerList)(types.NewList()) | ||
} | ||
|
||
func (pl *PeerList) Get(gid string) Peer { | ||
return (*types.List)(pl).Get(gid).(Peer) | ||
} | ||
|
||
func (pl *PeerList) Set(gid string, sp Peer) { | ||
(*types.List)(pl).Add(gid, sp) | ||
} | ||
|
||
func (pl *PeerList) Count() int { | ||
return (*types.List)(pl).Count() | ||
} |
Oops, something went wrong.