diff options
author | obscuren <geffobscura@gmail.com> | 2014-01-18 07:19:29 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-01-18 07:19:29 +0800 |
commit | ee61cfcfa776a1626fe3de7138942c1d796afdca (patch) | |
tree | 5b0d0a89ee5e38498af9765abd99a6f6ae77477c /server.go | |
parent | 5e5f386108ea4b75167bad96a2bf7cd801306045 (diff) | |
download | go-tangerine-ee61cfcfa776a1626fe3de7138942c1d796afdca.tar.gz go-tangerine-ee61cfcfa776a1626fe3de7138942c1d796afdca.tar.zst go-tangerine-ee61cfcfa776a1626fe3de7138942c1d796afdca.zip |
Added get peers and peers msg.
Diffstat (limited to 'server.go')
-rw-r--r-- | server.go | 43 |
1 files changed, 39 insertions, 4 deletions
@@ -20,6 +20,10 @@ func eachPeer(peers *list.List, callback func(*Peer, *list.Element)) { } } +const ( + processReapingTimeout = 60 // TODO increase +) + type Server struct { // Channel for shutting down the server shutdownChan chan bool @@ -66,6 +70,13 @@ func (s *Server) AddPeer(conn net.Conn) { } } +func (s *Server) ProcessPeerList(addrs []string) { + for _, addr := range addrs { + // TODO Probably requires some sanity checks + s.ConnectToPeer(addr) + } +} + func (s *Server) ConnectToPeer(addr string) error { peer := NewOutboundPeer(addr, s) @@ -74,16 +85,40 @@ func (s *Server) ConnectToPeer(addr string) error { return nil } +func (s *Server) OutboundPeers() []*Peer { + // Create a new peer slice with at least the length of the total peers + outboundPeers := make([]*Peer, s.peers.Len()) + length := 0 + eachPeer(s.peers, func(p *Peer, e *list.Element) { + if !p.inbound { + outboundPeers[length] = p + length++ + } + }) + + return outboundPeers[:length] +} + +func (s *Server) InboundPeers() []*Peer { + // Create a new peer slice with at least the length of the total peers + inboundPeers := make([]*Peer, s.peers.Len()) + length := 0 + eachPeer(s.peers, func(p *Peer, e *list.Element) { + if p.inbound { + inboundPeers[length] = p + length++ + } + }) + + return inboundPeers[:length] +} + func (s *Server) Broadcast(msgType ethwire.MsgType, data []byte) { eachPeer(s.peers, func(p *Peer, e *list.Element) { p.QueueMessage(ethwire.NewMessage(msgType, data)) }) } -const ( - processReapingTimeout = 1 // TODO increase -) - func (s *Server) ReapDeadPeers() { for { eachPeer(s.peers, func(p *Peer, e *list.Element) { |