2018-01-26 18:04:13 +00:00
|
|
|
package network
|
|
|
|
|
|
|
|
import (
|
2018-02-01 18:54:23 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/util"
|
2018-01-26 18:04:13 +00:00
|
|
|
)
|
|
|
|
|
2018-01-31 08:27:08 +00:00
|
|
|
// Peer is the local representation of a remote node. It's an interface that may
|
|
|
|
// be backed by any concrete transport: local, HTTP, tcp.
|
|
|
|
type Peer interface {
|
|
|
|
id() uint32
|
2018-01-31 19:11:08 +00:00
|
|
|
addr() util.Endpoint
|
2018-01-31 08:27:08 +00:00
|
|
|
disconnect()
|
2018-02-02 10:02:25 +00:00
|
|
|
callVersion(*Message) error
|
|
|
|
callGetaddr(*Message) error
|
|
|
|
callVerack(*Message) error
|
|
|
|
callGetdata(*Message) error
|
2018-02-04 19:54:51 +00:00
|
|
|
callGetblocks(*Message) error
|
|
|
|
callGetheaders(*Message) error
|
2018-01-31 08:27:08 +00:00
|
|
|
}
|
|
|
|
|
2018-01-31 19:11:08 +00:00
|
|
|
// LocalPeer is the simplest kind of peer, mapped to a server in the
|
|
|
|
// same process-space.
|
2018-01-31 08:27:08 +00:00
|
|
|
type LocalPeer struct {
|
2018-01-31 19:11:08 +00:00
|
|
|
s *Server
|
|
|
|
nonce uint32
|
|
|
|
endpoint util.Endpoint
|
2018-01-31 08:27:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewLocalPeer return a LocalPeer.
|
2018-01-31 19:11:08 +00:00
|
|
|
func NewLocalPeer(s *Server) *LocalPeer {
|
2018-01-31 08:27:08 +00:00
|
|
|
e, _ := util.EndpointFromString("1.1.1.1:1111")
|
2018-01-31 19:11:08 +00:00
|
|
|
return &LocalPeer{endpoint: e, s: s}
|
2018-01-31 08:27:08 +00:00
|
|
|
}
|
|
|
|
|
2018-02-02 10:02:25 +00:00
|
|
|
func (p *LocalPeer) callVersion(msg *Message) error {
|
|
|
|
return p.s.handleVersionCmd(msg, p)
|
2018-01-31 08:27:08 +00:00
|
|
|
}
|
|
|
|
|
2018-02-02 10:02:25 +00:00
|
|
|
func (p *LocalPeer) callVerack(msg *Message) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *LocalPeer) callGetaddr(msg *Message) error {
|
|
|
|
return p.s.handleGetaddrCmd(msg, p)
|
|
|
|
}
|
|
|
|
|
2018-02-04 19:54:51 +00:00
|
|
|
func (p *LocalPeer) callGetblocks(msg *Message) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *LocalPeer) callGetheaders(msg *Message) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-02-02 10:02:25 +00:00
|
|
|
func (p *LocalPeer) callGetdata(msg *Message) error {
|
|
|
|
return nil
|
2018-01-31 08:27:08 +00:00
|
|
|
}
|
|
|
|
|
2018-01-31 19:11:08 +00:00
|
|
|
func (p *LocalPeer) id() uint32 { return p.nonce }
|
|
|
|
func (p *LocalPeer) addr() util.Endpoint { return p.endpoint }
|
|
|
|
func (p *LocalPeer) disconnect() {}
|