diff --git a/.github/workflows/build-short.yml b/.github/workflows/build-short.yml index 08c2726..c064b41 100644 --- a/.github/workflows/build-short.yml +++ b/.github/workflows/build-short.yml @@ -11,4 +11,4 @@ jobs: with: go-version: 1.16.5 - run: go build . - - run: cd server && go test -v -race \ No newline at end of file + - run: go test -v -race ./... \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d1b0dc7..0b407d6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 ./... diff --git a/server/federation.go b/server/federation.go index 6348764..288561f 100644 --- a/server/federation.go +++ b/server/federation.go @@ -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. diff --git a/server/server.go b/server/server.go index fea59c6..8efea8d 100644 --- a/server/server.go +++ b/server/server.go @@ -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 { diff --git a/server/udp.go b/server/udp.go index 6e7d454..eef6552 100644 --- a/server/udp.go +++ b/server/udp.go @@ -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