@@ -36,6 +36,18 @@ type asnAnnotator struct {
3636 asnames ipinfo.ASNames
3737}
3838
39+ // NewIPv4 makes a new IPv4-only Annotator that uses IP addresses to lookup ASN metadata for
40+ // that IP based on the current copy of RouteViews data stored in the given providers.
41+ func NewIPv4 (ctx context.Context , as4 content.Provider ) ASNAnnotator {
42+ a := & asnAnnotator {
43+ as4 : as4 ,
44+ }
45+ var err error
46+ a .asn4 , err = load (ctx , as4 , nil )
47+ rtx .Must (err , "Could not load Routeviews IPv4 ASN db" )
48+ return a
49+ }
50+
3951// New makes a new Annotator that uses IP addresses to lookup ASN metadata for
4052// that IP based on the current copy of RouteViews data stored in the given providers.
4153func New (ctx context.Context , as4 content.Provider , as6 content.Provider , asnamedata content.Provider , localIPs []net.IP ) ASNAnnotator {
@@ -97,6 +109,10 @@ func (a *asnAnnotator) annotateIPHoldingLock(src string) *annotator.Network {
97109 metrics .ASNSearches .WithLabelValues ("ipv4-success" ).Inc ()
98110 return ann
99111 }
112+ if a .asn6 == nil {
113+ ann .Missing = true
114+ return ann
115+ }
100116
101117 ipnet , err = a .asn6 .Search (src )
102118 if err != nil {
@@ -126,15 +142,19 @@ func (a *asnAnnotator) Reload(ctx context.Context) {
126142 log .Println ("Could not reload v4 routeviews:" , err )
127143 return
128144 }
129- new6 , err := load (ctx , a .as6 , a .asn6 )
130- if err != nil {
131- log .Println ("Could not reload v6 routeviews:" , err )
132- return
133- }
134- newnames , err := loadNames (ctx , a .asnamedata , a .asnames )
135- if err != nil {
136- log .Println ("Could not reload asnames from ipinfo:" , err )
137- return
145+ var new6 routeview.Index
146+ var newnames ipinfo.ASNames
147+ if a .as6 != nil {
148+ new6 , err = load (ctx , a .as6 , a .asn6 )
149+ if err != nil {
150+ log .Println ("Could not reload v6 routeviews:" , err )
151+ return
152+ }
153+ newnames , err = loadNames (ctx , a .asnamedata , a .asnames )
154+ if err != nil {
155+ log .Println ("Could not reload asnames from ipinfo:" , err )
156+ return
157+ }
138158 }
139159 // Don't acquire the lock until after the data is in RAM.
140160 a .m .Lock ()
0 commit comments