Updates based on code review
This commit is contained in:
parent
2e52c1639c
commit
2a1d6fa7d4
5 changed files with 25 additions and 23 deletions
2
.github/workflows/build-short.yml
vendored
2
.github/workflows/build-short.yml
vendored
|
@ -11,4 +11,4 @@ jobs:
|
|||
with:
|
||||
go-version: 1.16.5
|
||||
- run: go build .
|
||||
- run: cd server && go test -v -race
|
||||
- run: go test -v -race ./...
|
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
|
@ -30,4 +30,4 @@ jobs:
|
|||
- run: go get github.com/golang/protobuf/protoc-gen-go google.golang.org/grpc/cmd/protoc-gen-go-grpc
|
||||
- run: go build .
|
||||
- run: ./protobuf/build.sh
|
||||
- run: cd server && go test -v -race
|
||||
- run: go test -v -race ./...
|
||||
|
|
|
@ -18,9 +18,9 @@ import (
|
|||
|
||||
// Peer holds relevant information about peers that we know about.
|
||||
type Peer struct {
|
||||
Address string
|
||||
Port string
|
||||
Ts time.Time
|
||||
Address string
|
||||
Port string
|
||||
LastSeen time.Time
|
||||
}
|
||||
|
||||
var (
|
||||
|
@ -68,8 +68,7 @@ func (s *Server) getNumSubs() int64 {
|
|||
return *s.NumPeerSubs
|
||||
}
|
||||
|
||||
// getAndSetExternalIp takes the ip and port of a peer running a UDP server and
|
||||
// pings it, so we can determine our own external IP address.
|
||||
// getAndSetExternalIp detects the server's external IP and stores it.
|
||||
func (s *Server) getAndSetExternalIp(ip, port string) error {
|
||||
pong, err := UDPPing(ip, port)
|
||||
if err != nil {
|
||||
|
@ -146,9 +145,9 @@ retry:
|
|||
}
|
||||
|
||||
newPeer := &Peer{
|
||||
Address: ipPort[0],
|
||||
Port: ipPort[1],
|
||||
Ts: time.Now(),
|
||||
Address: ipPort[0],
|
||||
Port: ipPort[1],
|
||||
LastSeen: time.Now(),
|
||||
}
|
||||
log.Printf("pinging peer %+v\n", newPeer)
|
||||
err = s.addPeer(newPeer, true, true)
|
||||
|
@ -377,7 +376,7 @@ func (s *Server) addPeer(newPeer *Peer, ping bool, subscribe bool) error {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
oldServer.Ts = time.Now()
|
||||
oldServer.LastSeen = time.Now()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -387,9 +386,9 @@ func (s *Server) addPeer(newPeer *Peer, ping bool, subscribe bool) error {
|
|||
func (s *Server) mergePeers(servers []*pb.ServerMessage) {
|
||||
for _, srvMsg := range servers {
|
||||
newPeer := &Peer{
|
||||
Address: srvMsg.Address,
|
||||
Port: srvMsg.Port,
|
||||
Ts: time.Now(),
|
||||
Address: srvMsg.Address,
|
||||
Port: srvMsg.Port,
|
||||
LastSeen: time.Now(),
|
||||
}
|
||||
err := s.addPeer(newPeer, false, true)
|
||||
// This shouldn't happen because we're not pinging them.
|
||||
|
|
|
@ -246,9 +246,9 @@ func (s *Server) Hello(ctx context.Context, args *pb.HelloMessage) (*pb.HelloMes
|
|||
port := args.Port
|
||||
host := args.Host
|
||||
newPeer := &Peer{
|
||||
Address: host,
|
||||
Port: port,
|
||||
Ts: time.Now(),
|
||||
Address: host,
|
||||
Port: port,
|
||||
LastSeen: time.Now(),
|
||||
}
|
||||
log.Println(newPeer)
|
||||
|
||||
|
@ -270,9 +270,9 @@ func (s *Server) PeerSubscribe(ctx context.Context, in *pb.ServerMessage) (*pb.S
|
|||
metrics.RequestsCount.With(prometheus.Labels{"method": "peer_subscribe"}).Inc()
|
||||
var msg = "Success"
|
||||
peer := &Peer{
|
||||
Address: in.Address,
|
||||
Port: in.Port,
|
||||
Ts: time.Now(),
|
||||
Address: in.Address,
|
||||
Port: in.Port,
|
||||
LastSeen: time.Now(),
|
||||
}
|
||||
|
||||
if _, loaded := s.PeerSubsLoadOrStore(peer); !loaded {
|
||||
|
@ -290,9 +290,9 @@ func (s *Server) AddPeer(ctx context.Context, args *pb.ServerMessage) (*pb.Strin
|
|||
metrics.RequestsCount.With(prometheus.Labels{"method": "add_peer"}).Inc()
|
||||
var msg = "Success"
|
||||
newPeer := &Peer{
|
||||
Address: args.Address,
|
||||
Port: args.Port,
|
||||
Ts: time.Now(),
|
||||
Address: args.Address,
|
||||
Port: args.Port,
|
||||
LastSeen: time.Now(),
|
||||
}
|
||||
err := s.addPeer(newPeer, true, true)
|
||||
if err != nil {
|
||||
|
|
|
@ -14,6 +14,9 @@ import (
|
|||
const maxBufferSize = 1024
|
||||
|
||||
// genesis blocktime (which is actually wrong)
|
||||
// magic constant for the UDPPing protocol. The above comment is taken from
|
||||
// the python code this was implemented off of.
|
||||
// https://github.com/lbryio/lbry-sdk/blob/7d49b046d44a4b7067d5dc1d6cd65ff0475c71c8/lbry/wallet/server/udp.py#L12
|
||||
const magic = 1446058291
|
||||
const protocolVersion = 1
|
||||
const defaultFlags = 0b00000000
|
||||
|
|
Loading…
Reference in a new issue