Skip to content

Commit d9c79bc

Browse files
committed
feat: add configurable peeringdb-url for local cache
1 parent 54ead24 commit d9c79bc

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

docs/docs/configuration.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ Global BIRD configuration
101101
|------|---------|------------|
102102
| string | | |
103103

104+
### `peeringdb-url`
105+
106+
PeeringDB API URL, can be set to a local PeeringDB cache server
107+
108+
| Type | Default | Validation |
109+
|------|---------|------------|
110+
| string | https://peeringdb.com/api/ | |
111+
104112
### `blocklist`
105113

106114
List of ASNs, prefixes, and IP addresses to block

pkg/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ type Config struct {
332332
WebUIFile string `yaml:"web-ui-file" description:"File to write web UI to (disabled if empty)" default:""`
333333
LogFile string `yaml:"log-file" description:"Log file location" default:"syslog"`
334334
GlobalConfig string `yaml:"global-config" description:"Global BIRD configuration" default:""`
335+
PeeringDBURL string `yaml:"peeringdb-url" description:"PeeringDB API URL, can be set to a local PeeringDB cache server" default:"https://peeringdb.com/api/"`
335336

336337
Blocklist []string `yaml:"blocklist" description:"List of ASNs, prefixes, and IP addresses to block" default:""`
337338
BlocklistURLs []string `yaml:"blocklist-urls" description:"List of URLs to fetch blocklists from" default:""`

pkg/peeringdb/peeringdb.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ func endpoint() string {
2525
}
2626
}
2727

28+
// Endpoint is a public value to allow overwriting to a cache server
29+
var Endpoint = endpoint()
30+
2831
type IxLanResponse struct {
2932
Data []IxLanData `json:"data"`
3033
}
@@ -69,7 +72,7 @@ var (
6972
// networkInfo returns PeeringDB for an ASN
7073
func networkInfo(asn uint32, queryTimeout uint, apiKey string) (*Data, error) {
7174
httpClient := http.Client{Timeout: time.Second * time.Duration(queryTimeout)}
72-
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf(endpoint()+"/net?asn=%d", asn), nil)
75+
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf(Endpoint+"/net?asn=%d", asn), nil)
7376

7477
if apiKey != "" {
7578
req.Header.Add("AUTHORIZATION", "Api-Key "+apiKey)
@@ -176,7 +179,7 @@ func Update(peerData *config.Peer, queryTimeout uint, apiKey string, useCache bo
176179
// NeverViaRouteServers gets a list of networks that report should never be reachable via route servers
177180
func NeverViaRouteServers(queryTimeout uint, apiKey string) ([]uint32, error) {
178181
httpClient := http.Client{Timeout: time.Second * time.Duration(queryTimeout)}
179-
req, err := http.NewRequest(http.MethodGet, endpoint()+"/net?info_never_via_route_servers=1", nil)
182+
req, err := http.NewRequest(http.MethodGet, Endpoint+"/net?info_never_via_route_servers=1", nil)
180183
if err != nil {
181184
return nil, fmt.Errorf("PeeringDB GET: %s", err)
182185
}
@@ -222,7 +225,7 @@ func NeverViaRouteServers(queryTimeout uint, apiKey string) ([]uint32, error) {
222225
// IXLANs gets PeeringDB IX LANs for an ASN
223226
func IXLANs(asn uint32, peeringDbQueryTimeout uint, apiKey string) ([]IxLanData, error) {
224227
httpClient := http.Client{Timeout: time.Second * time.Duration(peeringDbQueryTimeout)}
225-
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf(endpoint()+"/netixlan?asn=%d", asn), nil)
228+
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf(Endpoint+"/netixlan?asn=%d", asn), nil)
226229
if err != nil {
227230
return nil, fmt.Errorf("PeeringDB GET (This peer might not have a PeeringDB page): %s", err)
228231
}

pkg/process/process.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ func Load(configBlob []byte) (*config.Config, error) {
123123
}
124124
}
125125

126+
// Set PeeringDB URL
127+
peeringdb.Endpoint = c.PeeringDBURL
128+
126129
// Set hostname if empty
127130
if c.Hostname == "" {
128131
hostname, err := os.Hostname()

0 commit comments

Comments
 (0)