|
@@ -24,11 +24,8 @@ var (
|
|
|
|
|
|
|
|
// Server manages all peer connections.
|
|
// Server manages all peer connections.
|
|
|
type Server struct {
|
|
type Server struct {
|
|
|
- // Config fields may not be modified while the server is running.
|
|
|
|
|
Config
|
|
Config
|
|
|
|
|
|
|
|
- // Hooks for testing. These are useful because we can inhibit
|
|
|
|
|
- // the whole protocol stack.
|
|
|
|
|
//newTransport func(net.Conn, *ecdsa.PublicKey) transport
|
|
//newTransport func(net.Conn, *ecdsa.PublicKey) transport
|
|
|
//newPeerHook func(*Peer)
|
|
//newPeerHook func(*Peer)
|
|
|
//listenFunc func(network, addr string) (net.Listener, error)
|
|
//listenFunc func(network, addr string) (net.Listener, error)
|
|
@@ -49,7 +46,6 @@ type Server struct {
|
|
|
discmix *enode.FairMix
|
|
discmix *enode.FairMix
|
|
|
dialsched *dialScheduler
|
|
dialsched *dialScheduler
|
|
|
|
|
|
|
|
- // Channels into the run loop.
|
|
|
|
|
quit chan struct{}
|
|
quit chan struct{}
|
|
|
//addtrusted chan *enode.Node
|
|
//addtrusted chan *enode.Node
|
|
|
//removetrusted chan *enode.Node
|
|
//removetrusted chan *enode.Node
|
|
@@ -59,7 +55,6 @@ type Server struct {
|
|
|
checkpointPostHandshake chan *conn
|
|
checkpointPostHandshake chan *conn
|
|
|
checkpointAddPeer chan *conn
|
|
checkpointAddPeer chan *conn
|
|
|
|
|
|
|
|
- // State of run loop and listenLoop.
|
|
|
|
|
//inboundHistory expHeap
|
|
//inboundHistory expHeap
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -385,29 +380,3 @@ func (server *Server) checkpoint(c *conn, stage chan<- *conn) error {
|
|
|
}
|
|
}
|
|
|
return <-c.cont
|
|
return <-c.cont
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-// sharedUDPConn implements a shared connection. Write sends messages to the underlying connection while read returns
|
|
|
|
|
-// messages that were found unprocessable and sent to the unhandled channel by the primary listener.
|
|
|
|
|
-type sharedUDPConn struct {
|
|
|
|
|
- *net.UDPConn
|
|
|
|
|
- unhandled chan discover.ReadPacket
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-// ReadFromUDP implements discover.UDPConn
|
|
|
|
|
-func (s *sharedUDPConn) ReadFromUDP(b []byte) (n int, addr *net.UDPAddr, err error) {
|
|
|
|
|
- packet, ok := <-s.unhandled
|
|
|
|
|
- if !ok {
|
|
|
|
|
- return 0, nil, errors.New("connection was closed")
|
|
|
|
|
- }
|
|
|
|
|
- l := len(packet.Data)
|
|
|
|
|
- if l > len(b) {
|
|
|
|
|
- l = len(b)
|
|
|
|
|
- }
|
|
|
|
|
- copy(b[:l], packet.Data[:l])
|
|
|
|
|
- return l, packet.Addr, nil
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-// Close implements discover.UDPConn
|
|
|
|
|
-func (s *sharedUDPConn) Close() error {
|
|
|
|
|
- return nil
|
|
|
|
|
-}
|
|
|