Skip to content

Commit 517d0bd

Browse files
committed
Rename and comment
1 parent 5476677 commit 517d0bd

File tree

14 files changed

+105
-250
lines changed

14 files changed

+105
-250
lines changed

cmd/nebula/cmd_resolve.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
// ResolveCommand contains the monitor sub-command configuration.
1919
var ResolveCommand = &cli.Command{
2020
Name: "resolve",
21-
Usage: "Resolves all **unresolved** multi addresses to their IP addresses and geo location information",
21+
Usage: "Resolves all multi addresses to their IP addresses and geo location information",
2222
Action: ResolveAction,
2323
Flags: []cli.Flag{
2424
&cli.IntFlag{
@@ -28,13 +28,6 @@ var ResolveCommand = &cli.Command{
2828
DefaultText: "100",
2929
Value: 100,
3030
},
31-
&cli.BoolFlag{
32-
Name: "full",
33-
Usage: "If set nebula starts resolving all multi addresses in the database",
34-
EnvVars: []string{"NEBULA_RESOLVE_FULL"},
35-
DefaultText: "false",
36-
Value: false,
37-
},
3831
},
3932
}
4033

@@ -79,11 +72,7 @@ func ResolveAction(c *cli.Context) error {
7972

8073
var err error
8174
var dbmaddrs models.MultiAddressSlice
82-
if c.Bool("full") {
83-
dbmaddrs, err = dbc.FetchMultiAddresses(c.Context, offset, limit)
84-
} else {
85-
dbmaddrs, err = dbc.FetchUnresolvedMultiAddresses(c.Context, offset, limit)
86-
}
75+
dbmaddrs, err = dbc.FetchMultiAddresses(c.Context, offset, limit)
8776
if err != nil {
8877
return errors.Wrap(err, "fetching multi addresses")
8978
}

pkg/crawl/db.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/dennis-tra/nebula-crawler/pkg/models"
1212
)
1313

14-
// updateCrawl writes crawl statistics to the database. TODO: comment
14+
// updateCrawl writes crawl statistics to the database
1515
func (s *Scheduler) updateCrawl(ctx context.Context, success bool) error {
1616
log.Infoln("Persisting crawl result...")
1717

@@ -49,7 +49,7 @@ func (s *Scheduler) persistCrawlProperties(ctx context.Context) error {
4949
}
5050
pps := map[string]map[string]int{
5151
"agent_version": avFull,
52-
"agent_version_core": avCore,
52+
"agent_version_core": avCore, // TODO: Not used currently
5353
"protocol": s.protocols,
5454
"error": s.errors,
5555
}

pkg/crawl/persister.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ import (
1919
var persisterID = atomic.NewInt32(0)
2020

2121
// Persister handles the insert/upsert/update operations for a particular crawl result.
22-
// We're doing it asynchronously as each insert can take multiple tens of milliseconds.
23-
// This would take too long to do synchronously during a crawl.
2422
type Persister struct {
2523
*service.Service
2624

pkg/crawl/utils.go

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package crawl
22

33
import (
4-
"time"
5-
64
"github.com/libp2p/go-libp2p-core/peer"
75
ma "github.com/multiformats/go-multiaddr"
86
manet "github.com/multiformats/go-multiaddr/net"
@@ -17,18 +15,7 @@ func (s *Scheduler) TotalErrors() int {
1715
return sum
1816
}
1917

20-
func addrsToMaddrs(addrs []string) ([]ma.Multiaddr, error) {
21-
maddrs := make([]ma.Multiaddr, len(addrs))
22-
for i, addr := range addrs {
23-
maddr, err := ma.NewMultiaddr(addr)
24-
if err != nil {
25-
return nil, err
26-
}
27-
maddrs[i] = maddr
28-
}
29-
return maddrs, nil
30-
}
31-
18+
// maddrsToAddrs maps a slice of multi addresses to their string representation.
3219
func maddrsToAddrs(maddrs []ma.Multiaddr) []string {
3320
addrs := make([]string, len(maddrs))
3421
for i, maddr := range maddrs {
@@ -37,11 +24,6 @@ func maddrsToAddrs(maddrs []ma.Multiaddr) []string {
3724
return addrs
3825
}
3926

40-
// millisSince returns the number of milliseconds between now and the given time.
41-
func millisSince(start time.Time) float64 {
42-
return float64(time.Since(start)) / float64(time.Millisecond)
43-
}
44-
4527
// filterPrivateMaddrs strips private multiaddrs from the given peer address information.
4628
func filterPrivateMaddrs(pi peer.AddrInfo) peer.AddrInfo {
4729
filtered := peer.AddrInfo{

pkg/db/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ package db
33
import (
44
"context"
55
"database/sql"
6-
_ "embed"
76
"fmt"
87
"sync"
98
"time"
109

1110
"contrib.go.opencensus.io/integrations/ocsql"
11+
_ "github.com/lib/pq"
1212
"github.com/libp2p/go-libp2p-core/peer"
1313
ma "github.com/multiformats/go-multiaddr"
1414
"github.com/pkg/errors"

pkg/db/db.go

Lines changed: 0 additions & 42 deletions
This file was deleted.

pkg/db/db_test.go

Lines changed: 0 additions & 60 deletions
This file was deleted.

pkg/maxmind/maxmind.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,9 @@ func NewClient() (*Client, error) {
3232
}, nil
3333
}
3434

35-
func (c *Client) AddrCountry(addr string) (string, error) {
36-
ip := net.ParseIP(addr)
37-
if ip == nil {
38-
return "", fmt.Errorf("invalid address %s", addr)
39-
}
40-
record, err := c.reader.City(ip)
41-
if err != nil {
42-
return "", err
43-
}
44-
return record.Country.IsoCode, nil
45-
}
46-
35+
// MaddrCountry resolve the give multi address to its corresponding
36+
// IP addresses (it could be multiple due to protocols like dnsaddr)
37+
// and returns a map of the form IP-address -> country ISO code.
4738
func (c *Client) MaddrCountry(ctx context.Context, maddr ma.Multiaddr) (map[string]string, error) {
4839
resolved := resolveAddrs(ctx, maddr)
4940
if len(resolved) == 0 {
@@ -61,6 +52,19 @@ func (c *Client) MaddrCountry(ctx context.Context, maddr ma.Multiaddr) (map[stri
6152
return countries, nil
6253
}
6354

55+
// AddrCountry takes an IP address string and tries to derive the country ISO code.
56+
func (c *Client) AddrCountry(addr string) (string, error) {
57+
ip := net.ParseIP(addr)
58+
if ip == nil {
59+
return "", fmt.Errorf("invalid address %s", addr)
60+
}
61+
record, err := c.reader.Country(ip)
62+
if err != nil {
63+
return "", err
64+
}
65+
return record.Country.IsoCode, nil
66+
}
67+
6468
func (c *Client) Close() error {
6569
return c.reader.Close()
6670
}

pkg/maxmind/maxmind_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,18 @@ func TestClient_MaddrCountry(t *testing.T) {
4444
require.NoError(t, err)
4545

4646
tests := []struct {
47-
addr string
48-
want string
49-
wantErr bool
47+
addr string
48+
wantAddr string
49+
wantCountry string
50+
wantErr bool
5051
}{
51-
{addr: "/ip4/46.17.96.99/tcp/6666/p2p/Qme8g49gm3q4Acp7xWBKg3nAa9fxZ1YmyDJdyGgoG6LsXh/p2p-circuit", want: "NL", wantErr: false},
52-
{addr: "/p2p-circuit/p2p/QmPG5bax9kfpQUVDrzfahmh44Ab6egDeZ2QDWeTY279HLJ", want: "", wantErr: true},
53-
{addr: "/dnsaddr/bootstrap.libp2p.io", want: "", wantErr: true},
52+
{addr: "/ip4/46.17.96.99/tcp/6666/p2p/Qme8g49gm3q4Acp7xWBKg3nAa9fxZ1YmyDJdyGgoG6LsXh/p2p-circuit", wantAddr: "46.17.96.99", wantCountry: "NL", wantErr: false},
53+
{addr: "/p2p-circuit/p2p/QmPG5bax9kfpQUVDrzfahmh44Ab6egDeZ2QDWeTY279HLJ", wantAddr: "", wantCountry: "", wantErr: true},
54+
{addr: "/dnsaddr/bootstrap.libp2p.io", wantAddr: "147.75.109.29", wantCountry: "US", wantErr: false},
5455
//{addr: "/dns4/k8s-dev-ipfsp2pt-c0b76d02d7-969229bd37f82282.elb.ca-central-1.amazonaws.com/tcp/4001", want: "", wantErr: true},
5556
}
5657
for _, tt := range tests {
57-
t.Run(fmt.Sprintf("%s | iso: %s | err: %v", tt.addr, tt.want, tt.wantErr), func(t *testing.T) {
58+
t.Run(fmt.Sprintf("%s | iso: %s | err: %v", tt.addr, tt.wantCountry, tt.wantErr), func(t *testing.T) {
5859
maddr, err := ma.NewMultiaddr(tt.addr)
5960
require.NoError(t, err)
6061

@@ -63,8 +64,8 @@ func TestClient_MaddrCountry(t *testing.T) {
6364
assert.Error(t, err)
6465
} else {
6566
assert.NoError(t, err)
67+
assert.Equal(t, tt.wantCountry, got[tt.wantAddr])
6668
}
67-
assert.Equal(t, tt.want, got)
6869
})
6970
}
7071
}

pkg/monitor/db.go

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)