Parcourir la source

Improve docs, rearrage file contents.

Thomas Frössman il y a 9 ans
Parent
révision
8833d4ee61
5 fichiers modifiés avec 84 ajouts et 65 suppressions
  1. 4
    20
      README.md
  2. 7
    5
      asn2asd.go
  3. 6
    4
      cidrreport.go
  4. 34
    5
      internet.go
  5. 33
    31
      ip2asn.go

+ 4
- 20
README.md Voir le fichier

@@ -1,28 +1,12 @@
1 1
 # internet :) [![Build Status](https://drone.io/github.com/thomasf/internet/status.png)](https://drone.io/github.com/thomasf/internet/latest)
2 2
 
3
+## Introduction
4
+
3 5
 This package contains a server and client for historical searches in bgp dumps.
4 6
 I'm not sure where this is going so for the moment this package is named
5 7
 internet to postpone the definition.
6 8
 
7
-## Features
8
-
9
-* Downloads BGP table dumps from http://data.ris.ripe.net/rrc00 and imports
10
-  them into redis for current and historical IP address to AS Number lookup.
11
-* Downloads http://www.cidr-report.org/as2.0/autnums.html (controlled to once
12
-  per day) and stores the entries in redis for current and historical AS Number
13
-  to AS Description lookup.
14
-* Caches all data downloads so that databases can be rebuilt easily.
15
-
16
-
17
-## Pre requirements
18
-
19
-* BGPDump - [Download](http://www.ris.ripe.net/source/bgpdump/), compile and
20
-  install it somewhere into PATH.
21
-* Redis
22
-
9
+## Documentation
23 10
 
24
-## Acknowledgments
11
+* http://godoc.org/github.com/thomasf/internet
25 12
 
26
-Basic design for the IP2ASN history and ASN2ASDescription parts were inspired
27
-from https://github.com/CIRCL/IP-ASN-history and
28
-https://github.com/CIRCL/ASN-Description-History .

+ 7
- 5
asn2asd.go Voir le fichier

@@ -6,11 +6,8 @@ import (
6 6
 	"github.com/garyburd/redigo/redis"
7 7
 )
8 8
 
9
-type ASN2ASDescClient struct {
10
-	conn redis.Conn
11
-}
12
-
13
-//NewASN2ASDescClient .
9
+//NewASN2ASDescClient returns a new client for quering the. The caller is
10
+//reposible for closing the conn when the client is not used anymore.
14 11
 func NewASN2ASDescClient(conn redis.Conn) *ASN2ASDescClient {
15 12
 	asnasd := ASN2ASDescClient{
16 13
 		conn: conn,
@@ -18,6 +15,11 @@ func NewASN2ASDescClient(conn redis.Conn) *ASN2ASDescClient {
18 15
 	return &asnasd
19 16
 }
20 17
 
18
+//ASN2ASDescClient is the query client.
19
+type ASN2ASDescClient struct {
20
+	conn redis.Conn
21
+}
22
+
21 23
 // importedDates fetches all imported dates from redis
22 24
 func (i *ASN2ASDescClient) importedDates() ([]string, error) {
23 25
 	return redis.Strings(i.conn.Do("SMEMBERS", "asd:imported_dates"))

+ 6
- 4
cidrreport.go Voir le fichier

@@ -16,14 +16,16 @@ import (
16 16
 	"golang.org/x/net/html"
17 17
 )
18 18
 
19
+// ASDescription contains the parsed result of an row inside a autnums.html file.
19 20
 type ASDescription struct {
20
-	ASN         int
21
-	Description string
22
-	CountryCode string
21
+	ASN         int    // AS Number
22
+	Description string // AS Description
23
+	CountryCode string // Country code (split from the as description field)
23 24
 }
24 25
 
26
+// CIDRReport encapuslates downloading and importing of autnums.html files.
25 27
 type CIDRReport struct {
26
-	Date time.Time
28
+	Date time.Time // Timestamp
27 29
 }
28 30
 
29 31
 // Path returns the absolute path to the target archive dump download file.

+ 34
- 5
internet.go Voir le fichier

@@ -1,8 +1,37 @@
1
-// Package internet gives access to information about internet by
2
-// downloading/parsing/putting ripe BGP dumps and cidr-report.org data into
3
-// redis databases. Redis query clients are also supplied.
4
-//
5
-// This is a work in progress, the API's are unstable.
1
+/*
2
+
3
+Package internet produces queryable information about the internet by
4
+fetching and downloading ripe BGP dumps and cidr-report.org data into redis
5
+databases.
6
+
7
+Features
8
+
9
+Download BGP table dumps from http://data.ris.ripe.net/rrc00. Entries are
10
+stored into redis for current and historical IP address to AS Number lookup.
11
+
12
+Download http://www.cidr-report.org/as2.0/autnums.html (controlled to once per
13
+day). Entries are stored in redis for current and historical AS Number to AS
14
+Description lookup.
15
+
16
+All downloads are cached so that databases can be rebuilt easily.
17
+
18
+Golang redis query clients are also also included.
19
+
20
+Pre requirements
21
+
22
+BGPDump: http://www.ris.ripe.net/source/bgpdump/. Download, compile and install
23
+it somewhere into PATH.
24
+
25
+A Redis server.
26
+
27
+
28
+Acknowledgments
29
+
30
+Basic design for the IP2ASN history and ASN2ASDescription parts were inspired
31
+from https://github.com/CIRCL/IP-ASN-history and
32
+https://github.com/CIRCL/ASN-Description-History.
33
+
34
+*/
6 35
 package internet
7 36
 
8 37
 import (

+ 33
- 31
ip2asn.go Voir le fichier

@@ -9,32 +9,9 @@ import (
9 9
 	"github.com/garyburd/redigo/redis"
10 10
 )
11 11
 
12
-// IP2ASNClient .
13
-type IP2ASNClient struct {
14
-	conn redis.Conn
15
-}
16
-
17
-func (i *IP2ASNClient) parseIP(IP string) (net.IP, error) {
18
-	I := net.ParseIP(IP)
19
-	if I == nil {
20
-		return nil, net.InvalidAddrError(IP)
21
-	}
22
-	return I, nil
23
-}
24
-
25
-func (i *IP2ASNClient) keys(IP net.IP) []net.IPNet {
26
-	var keys []net.IPNet
27
-	for _, n := range netmasks {
28
-		ipn := net.IPNet{
29
-			IP:   IP.Mask(n),
30
-			Mask: n,
31
-		}
32
-		keys = append(keys, ipn)
33
-	}
34
-	return keys
35
-}
36
-
37
-// NewIP2ASNClient .
12
+// NewIP2ASNClient returns a new client for IP address to AS Number queries.
13
+// The caller is reposible for closing the conn when the client is not used
14
+// anymore.
38 15
 func NewIP2ASNClient(conn redis.Conn) *IP2ASNClient {
39 16
 	ipasn := &IP2ASNClient{
40 17
 		conn: conn,
@@ -42,6 +19,18 @@ func NewIP2ASNClient(conn redis.Conn) *IP2ASNClient {
42 19
 	return ipasn
43 20
 }
44 21
 
22
+// ASNResult contains the lookup results from resolving an IP address to a ASN.
23
+type ASNResult struct {
24
+	Mask net.IPNet
25
+	ASN  int
26
+	Date time.Time // Recorded time for when
27
+}
28
+
29
+// IP2ASNClient is the query client.
30
+type IP2ASNClient struct {
31
+	conn redis.Conn
32
+}
33
+
45 34
 // Current returns the latest known result for an IP2ASN lookup.
46 35
 func (i *IP2ASNClient) Current(IP string) *ASNResult {
47 36
 	ip, err := i.parseIP(IP)
@@ -80,11 +69,24 @@ func (i *IP2ASNClient) AllHistory(IP string) []ASNResult {
80 69
 	return result
81 70
 }
82 71
 
83
-// ASNResult contains the lookup results from resolving an IP address to a ASN.
84
-type ASNResult struct {
85
-	Mask net.IPNet
86
-	ASN  int
87
-	Date time.Time // Recorded time for when
72
+func (i *IP2ASNClient) parseIP(IP string) (net.IP, error) {
73
+	I := net.ParseIP(IP)
74
+	if I == nil {
75
+		return nil, net.InvalidAddrError(IP)
76
+	}
77
+	return I, nil
78
+}
79
+
80
+func (i *IP2ASNClient) keys(IP net.IP) []net.IPNet {
81
+	var keys []net.IPNet
82
+	for _, n := range netmasks {
83
+		ipn := net.IPNet{
84
+			IP:   IP.Mask(n),
85
+			Mask: n,
86
+		}
87
+		keys = append(keys, ipn)
88
+	}
89
+	return keys
88 90
 }
89 91
 
90 92
 // Stringer.