Run gofmt

This commit is contained in:
Jeffrey Picard 2021-11-24 18:24:06 -05:00
parent 0a1ba43d66
commit 72ea236d86
8 changed files with 150 additions and 158 deletions

View file

@ -31,4 +31,3 @@ var (
Help: "Number of peers that are subscribed to us.",
})
)

View file

@ -33,6 +33,7 @@ type Args struct {
StartPrometheus bool
StartUDP bool
WritePeers bool
DisableFederation bool
}
const (

View file

@ -32,7 +32,6 @@ var (
}
)
// peerKey takes a ServerMessage object and returns the key that for that peer
// in our peer table.
func peerKey(msg *pb.ServerMessage) string {
@ -117,7 +116,6 @@ retry:
}
cancel()
f, err := os.Open(peerFile)
if err != nil {
log.Println(err)
@ -135,7 +133,7 @@ retry:
}
for _, line := range text {
ipPort := strings.Split(line,":")
ipPort := strings.Split(line, ":")
if len(ipPort) != 2 {
log.Println("Malformed entry in peer file")
continue
@ -333,7 +331,7 @@ func (s *Server) addPeer(msg *pb.ServerMessage, ping bool, subscribe bool) error
// could end up subscribed to our self, which is silly.
nilIP := net.IP{}
//localIP0 := net.IPv4(0,0,0,0)
localIP1 := net.IPv4(127,0,0,1)
localIP1 := net.IPv4(127, 0, 0, 1)
if s.ExternalIP.Equal(nilIP) || s.ExternalIP.Equal(localIP1) {
err := s.getAndSetExternalIp(msg)
if err != nil {

View file

@ -75,7 +75,7 @@ func TestAddPeer(t *testing.T) {
tests := []struct {
name string
want int
} {
}{
{
name: "Add 10 peers",
want: 10,
@ -87,9 +87,9 @@ func TestAddPeer(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T){
t.Run(tt.name, func(t *testing.T) {
server := MakeHubServer(ctx, args)
server.ExternalIP = net.IPv4(0,0,0,0)
server.ExternalIP = net.IPv4(0, 0, 0, 0)
metrics.PeersKnown.Set(0)
for i := 0; i < 10; i++ {
@ -134,7 +134,7 @@ func TestPeerWriter(t *testing.T) {
tests := []struct {
name string
want int
} {
}{
{
name: "Add 10 peers",
want: 10,
@ -146,9 +146,9 @@ func TestPeerWriter(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T){
t.Run(tt.name, func(t *testing.T) {
server := MakeHubServer(ctx, args)
server.ExternalIP = net.IPv4(0,0,0,0)
server.ExternalIP = net.IPv4(0, 0, 0, 0)
for i := 0; i < 10; i++ {
var msg *pb.ServerMessage
@ -188,12 +188,11 @@ func TestAddPeerEndpoint(t *testing.T) {
args2 := makeDefaultArgs()
args2.Port = "50052"
tests := []struct {
name string
wantServerOne int64
wantServerTwo int64
} {
}{
{
// outside -> server1.AddPeer(server2, ping=true) : server1 = 1, server2 = 0
// server1 -> server2.Hello(server1) : server1 = 1, server2 = 0
@ -211,7 +210,7 @@ func TestAddPeerEndpoint(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T){
t.Run(tt.name, func(t *testing.T) {
server := MakeHubServer(ctx, args)
server2 := MakeHubServer(ctx, args2)
metrics.PeersKnown.Set(0)
@ -262,13 +261,12 @@ func TestAddPeerEndpoint2(t *testing.T) {
args2.Port = "50052"
args3.Port = "50053"
tests := []struct {
name string
wantServerOne int64
wantServerTwo int64
wantServerThree int64
} {
}{
{
name: "Add 2 peers",
wantServerOne: 2,
@ -278,7 +276,7 @@ func TestAddPeerEndpoint2(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T){
t.Run(tt.name, func(t *testing.T) {
server := MakeHubServer(ctx, args)
server2 := MakeHubServer(ctx, args2)
server3 := MakeHubServer(ctx, args3)
@ -335,7 +333,6 @@ func TestAddPeerEndpoint2(t *testing.T) {
}
// TestAddPeerEndpoint3 tests the ability to add peers
func TestAddPeerEndpoint3(t *testing.T) {
ctx := context.Background()
@ -345,13 +342,12 @@ func TestAddPeerEndpoint3(t *testing.T) {
args2.Port = "50052"
args3.Port = "50053"
tests := []struct {
name string
wantServerOne int64
wantServerTwo int64
wantServerThree int64
} {
}{
{
name: "Add 1 peer to each",
wantServerOne: 2,
@ -361,7 +357,7 @@ func TestAddPeerEndpoint3(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T){
t.Run(tt.name, func(t *testing.T) {
server := MakeHubServer(ctx, args)
server2 := MakeHubServer(ctx, args2)
server3 := MakeHubServer(ctx, args3)
@ -426,7 +422,6 @@ func TestAddPeerEndpoint3(t *testing.T) {
}
// TestAddPeer tests the ability to add peers
func TestUDPServer(t *testing.T) {
ctx := context.Background()
@ -439,7 +434,7 @@ func TestUDPServer(t *testing.T) {
tests := []struct {
name string
want string
} {
}{
{
name: "hubs server external ip",
want: "127.0.0.1",
@ -447,7 +442,7 @@ func TestUDPServer(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T){
t.Run(tt.name, func(t *testing.T) {
server := MakeHubServer(ctx, args)
server2 := MakeHubServer(ctx, args2)
go server.Run()

View file

@ -967,4 +967,3 @@ func removeBlocked(searchHits []*record) ([]*record, []*record, map[string]*pb.B
return newHits, blockedHits, blockedChannels
}

View file

@ -45,7 +45,6 @@ type Server struct {
pb.UnimplementedHubServer
}
func getVersion() string {
return meta.Version
}
@ -202,7 +201,7 @@ func MakeHubServer(ctx context.Context, args *Args) *Server {
PeerSubs: make(map[string]*FederatedServer),
PeerSubsMut: sync.RWMutex{},
NumPeerSubs: numSubs,
ExternalIP: net.IPv4(127,0,0,1),
ExternalIP: net.IPv4(127, 0, 0, 1),
}
// Start up our background services

View file

@ -12,6 +12,7 @@ import (
)
const maxBufferSize = 1024
// genesis blocktime (which is actually wrong)
const magic = 1446058291
const protocolVersion = 1
@ -240,7 +241,7 @@ func UDPServer(args *Args) error {
}
sAddr := addr.IP.String()
pong := makeSPVPong(0,0, tip, sAddr, args.Country)
pong := makeSPVPong(0, 0, tip, sAddr, args.Country)
data := pong.Encode()
_, err = conn.WriteToUDP(data, addr)

View file

@ -19,7 +19,7 @@ func TestUDPPing(t *testing.T) {
wantProtocolVersion int
wantHeightMin int
wantFlags byte
} {
}{
{
name: "Correctly parse information from production server.",
wantIP: "SETME",
@ -31,7 +31,7 @@ func TestUDPPing(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T){
t.Run(tt.name, func(t *testing.T) {
toAddr := "spv16.lbry.com"
toPort := "50001"