diff -pruN 0.0~git20170120.15a8ca0-1/canid/main.go 0.0~git20180613.007c9af-1/canid/main.go --- 0.0~git20170120.15a8ca0-1/canid/main.go 2018-01-24 11:31:14.000000000 +0000 +++ 0.0~git20180613.007c9af-1/canid/main.go 2018-02-09 22:03:00.000000000 +0000 @@ -3,57 +3,251 @@ package main import ( "encoding/json" "flag" - "github.com/britram/canid" "io" "log" "net/http" "os" "os/signal" "strconv" + + "github.com/britram/canid" ) -// RIPEstat backend moved to ripestat.go +// WelcomePage contains the Canid welcome page, which explains what Canid is, +// and gives a simple web interface to the service. +const WelcomePage = ` + + + + + Canid, the Caching Additional Network Information Daemon + + + + + + + + + +
+ +

Canidbeta

+ +

Canid, the Caching Additional Network Information Daemon, provides a + simple HTTP API for getting information about Internet names and + numbers. See the GitHub + repository for source code and more information

+ +

This landing page provides a browser-based interface to this instance + of the cache, backed by RIPEstat. You + can perform prefix lookups using the form below.

+ +
+ +
+ +
+
+
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ + + + +
+
+ + -// AddressCache moved to addresscache.go +` -const CANID_STORAGE_VERSION = 1 +const canidStorageVersion = 1 -type CanidStorage struct { +type canidStorage struct { Version int Prefixes *canid.PrefixCache Addresses *canid.AddressCache } -func (storage *CanidStorage) undump(in io.Reader) error { +func (storage *canidStorage) undump(in io.Reader) error { dec := json.NewDecoder(in) return dec.Decode(storage) } -func (storage *CanidStorage) dump(out io.Writer) error { +func (storage *canidStorage) dump(out io.Writer) error { enc := json.NewEncoder(out) return enc.Encode(*storage) } -func newStorage(expiry int, limit int) *CanidStorage { - storage := new(CanidStorage) - storage.Version = CANID_STORAGE_VERSION +func newStorage(expiry int, limit int) *canidStorage { + storage := new(canidStorage) + storage.Version = canidStorageVersion storage.Prefixes = canid.NewPrefixCache(expiry, limit) storage.Addresses = canid.NewAddressCache(expiry, limit, storage.Prefixes) return storage } +func welcomeServer(w http.ResponseWriter, req *http.Request) { + w.Header().Set("Content-Type", "text/html") + w.WriteHeader(http.StatusOK) + w.Write([]byte(WelcomePage)) +} + func main() { fileflag := flag.String("file", "", "backing store for caches (JSON file)") expiryflag := flag.Int("expiry", 86400, "expire cache entries after n sec") limitflag := flag.Int("concurrency", 16, "simultaneous backend request limit") - portflag := flag.Int("port", 8081, "port to listen on") + portflag := flag.Int("port", 8043, "port to listen on") // parse command line flag.Parse() - // set up sigterm handling + // set up sigint handling interrupt := make(chan os.Signal, 1) signal.Notify(interrupt, os.Interrupt) @@ -76,11 +270,12 @@ func main() { } // check for cache version mismatch - if storage.Version != CANID_STORAGE_VERSION { - log.Fatal("storage version mismatch for cache file %s: delete and try again", *fileflag) + if storage.Version != canidStorageVersion { + log.Fatalf("storage version mismatch for cache file %s: delete and try again", *fileflag) } go func() { + http.HandleFunc("/", welcomeServer) http.HandleFunc("/prefix.json", storage.Prefixes.LookupServer) http.HandleFunc("/address.json", storage.Addresses.LookupServer) log.Fatal(http.ListenAndServe(":"+strconv.Itoa(*portflag), nil)) diff -pruN 0.0~git20170120.15a8ca0-1/canid/welcome.html 0.0~git20180613.007c9af-1/canid/welcome.html --- 0.0~git20170120.15a8ca0-1/canid/welcome.html 1970-01-01 00:00:00.000000000 +0000 +++ 0.0~git20180613.007c9af-1/canid/welcome.html 2018-02-09 22:03:00.000000000 +0000 @@ -0,0 +1,187 @@ + + + + + Canid, the Caching Additional Network Information Daemon + + + + + + + + + +
+ +

Canidbeta

+ +

Canid, the Caching Additional Network Information Daemon, provides a + simple HTTP API for getting information about Internet names and + numbers. See the GitHub + repository for source code and more information

+ +

This landing page provides a browser-based interface to this instance + of the cache, backed by RIPEstat. You + can perform prefix lookups using the form below.

+ +
+ +
+ +
+
+
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ + + + +
+
+ + diff -pruN 0.0~git20170120.15a8ca0-1/debian/changelog 0.0~git20180613.007c9af-1/debian/changelog --- 0.0~git20170120.15a8ca0-1/debian/changelog 2018-01-24 12:05:49.000000000 +0000 +++ 0.0~git20180613.007c9af-1/debian/changelog 2018-06-13 09:00:44.000000000 +0000 @@ -1,3 +1,16 @@ +canid (0.0~git20180613.007c9af-1) unstable; urgency=medium + + * New upstream release from git snapshot 007c9af + * Installs new manpage canid.1 + * debian/control: + - Updated Standards Version to 4.1.4 + - Updated Vcs-* URLs from alioth to salsa + + The work for this change was supported by the European Union under grant + agreement No. 688421. This support does not imply endorsement. + + -- Iain R. Learmonth Wed, 13 Jun 2018 10:00:44 +0100 + canid (0.0~git20170120.15a8ca0-1) unstable; urgency=medium * Initial release (Closes: #888258) diff -pruN 0.0~git20170120.15a8ca0-1/debian/control 0.0~git20180613.007c9af-1/debian/control --- 0.0~git20170120.15a8ca0-1/debian/control 2018-01-24 11:58:17.000000000 +0000 +++ 0.0~git20180613.007c9af-1/debian/control 2018-06-13 08:58:49.000000000 +0000 @@ -6,10 +6,10 @@ Uploaders: Iain R. Learmonth = 11), dh-golang, golang-any -Standards-Version: 4.1.3 +Standards-Version: 4.1.4 Homepage: https://github.com/britram/canid -Vcs-Browser: https://anonscm.debian.org/cgit/pkg-netmeasure/canid.git -Vcs-Git: https://anonscm.debian.org/git/pkg-netmeasure/canid.git +Vcs-Browser: https://salsa.debian.org/ineteng-team/canid +Vcs-Git: https://salsa.debian.org/ineteng-team/canid.git XS-Go-Import-Path: github.com/britram/canid Testsuite: autopkgtest-pkg-go diff -pruN 0.0~git20170120.15a8ca0-1/debian/manpages 0.0~git20180613.007c9af-1/debian/manpages --- 0.0~git20170120.15a8ca0-1/debian/manpages 1970-01-01 00:00:00.000000000 +0000 +++ 0.0~git20180613.007c9af-1/debian/manpages 2018-06-13 08:43:10.000000000 +0000 @@ -0,0 +1 @@ +doc/canid.1 diff -pruN 0.0~git20170120.15a8ca0-1/doc/canid.1 0.0~git20180613.007c9af-1/doc/canid.1 --- 0.0~git20170120.15a8ca0-1/doc/canid.1 1970-01-01 00:00:00.000000000 +0000 +++ 0.0~git20180613.007c9af-1/doc/canid.1 2018-02-09 22:03:00.000000000 +0000 @@ -0,0 +1,79 @@ +.\" generated with Ronn/v0.7.3 +.\" http://github.com/rtomayko/ronn/tree/0.7.3 +. +.TH "CANID" "1" "February 2018" "" "" +. +.SH "NAME" +\fBcanid\fR \- the caching additional network information daemon +. +.SH "SYNOPSIS" +\fBcanid\fR [\-file \fIcachefile\fR] [\-expiry \fIsec\fR] [\-concurrency \fIn\fR] [\-port \fIport\fR] +. +.SH "DESCRIPTION" +Canid provides a simple web service for caching and simplifying information retrieved from other services (see \fIBACKENDS\fR) about Internet hostnames and IP addresses\. It is designed for use when looking up many addresses and/ +. +.P +On launch, Canid begins serving on the specified port\. It shuts down cleanly on SIGINT (^C on the console)\. +. +.SH "OPTIONS" +. +.IP "\(bu" 4 +\fB\-file\fR \fIcachefile\fR (default: no backing store) Use the given JSON file as a backing store for the cache\. Loads the cache from this file on startup, and saves it on termination\. +. +.IP "\(bu" 4 +\fB\-expiry\fR \fIsec\fR (default: 86400, 1 day) Expire cache entries after \fIsec\fR seconds\. +. +.IP "\(bu" 4 +\fB\-concurrency\fR \fIn\fR (default: 16) Allow at most \fIn\fR simultaneous pending requests per backend\. +. +.IP "\(bu" 4 +\fB\-port\fR \fIport\fR (default: 8043) TCP port to listen on +. +.IP "" 0 +. +.SH "RESOURCES" +Canid provides three resources via HTTP: +. +.IP "\(bu" 4 +\fB/\fR +. +.IP +The root resource is an HTML page providing a simple web front\-end to the service\. +. +.IP "\(bu" 4 +\fB/prefix\.json?addr=\fR +. +.IP +Look up information about the prefix associated with an address, and return it as a JSON object\. This object presently contains a \fBPrefix\fR key with the routed prefix associated with the address, an \fBASN\fR key with a BGP autonomous system number associated with the address, and a \fBCountryCode\fR key for an ISO 3166 country code associated with the address\. +. +.IP "\(bu" 4 +\fB/address\.json?name=\fR +. +.IP +Look up an Internet hostname via DNS, and return the IPv4 and IPv6 addresses associated with it as a JSON object\. This object contains a \fBName\fR key with the name looked up, and an \fBAddresses\fR key containing an array of IPv4 and/or IPv6 addresses as strings\. Looking up an address for a name will cause prefix information for all addresses found to be cached, as well\. +. +.IP "" 0 +. +.P +All JSON resources also contain a \fBCached\fR key, the time at which the data entry was put into the cache in [RFC3339][https://datatracker\.ietf\.org/doc/RFC3339] format\. +. +.SH "BACKENDS" +The \fBprefix\.json\fR resource currently uses the Prefix Overview and Geolocation API entry points from [RIPEstat][https://stat\.ripe\.net]\. +. +.P +The \fBaddress\.json\fR resource uses DNS, as provided by the Go standard library\'s \fBnet\.LookupIP()\fR (i\.e\., the system resolver) +. +.SH "AUTHOR" +Brian Trammell \fIbrian@trammell\.ch\fR +. +.SH "LICENSE" +Copyright (c) 2016 \- 2018 Brian Trammell +. +.P +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +. +.P +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software\. +. +.P +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT\. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE\. diff -pruN 0.0~git20170120.15a8ca0-1/doc/canid.1.html 0.0~git20180613.007c9af-1/doc/canid.1.html --- 0.0~git20170120.15a8ca0-1/doc/canid.1.html 1970-01-01 00:00:00.000000000 +0000 +++ 0.0~git20180613.007c9af-1/doc/canid.1.html 2018-02-09 22:03:00.000000000 +0000 @@ -0,0 +1,180 @@ + + + + + + canid(1) - the caching additional network information daemon + + + + +
+ + + +
    +
  1. canid(1)
  2. +
  3. +
  4. canid(1)
  5. +
+ +

NAME

+

+ canid - the caching additional network information daemon +

+ +

SYNOPSIS

+ +

canid [-file cachefile] [-expiry sec] [-concurrency n] [-port port]

+ +

DESCRIPTION

+ +

Canid provides a simple web service for caching and simplifying information +retrieved from other services (see BACKENDS) about Internet hostnames and +IP addresses. It is designed for use when looking up many addresses and/

+ +

On launch, Canid begins serving on the specified port. It shuts down cleanly +on SIGINT (^C on the console).

+ +

OPTIONS

+ +
    +
  • -file cachefile (default: no backing store) +Use the given JSON file as a backing store for the cache. +Loads the cache from this file on startup, and saves it on termination.

  • +
  • -expiry sec (default: 86400, 1 day) +Expire cache entries after sec seconds.

  • +
  • -concurrency n (default: 16) +Allow at most n simultaneous pending requests per backend.

  • +
  • -port port (default: 8043) +TCP port to listen on

  • +
+ + +

RESOURCES

+ +

Canid provides three resources via HTTP:

+ +
    +
  • /

    + +

    The root resource is an HTML page providing a simple web +front-end to the service.

  • +
  • /prefix.json?addr=

    + +

    Look up information about the prefix associated with an address, and +return it as a JSON object. This object presently contains a Prefix key +with the routed prefix associated with the address, an ASN key with a +BGP autonomous system number associated with the address, and a +CountryCode key for an ISO 3166 country code associated with the +address.

  • +
  • /address.json?name=

    + +

    Look up an Internet hostname via DNS, and return the IPv4 and IPv6 +addresses associated with it as a JSON object. This object contains a +Name key with the name looked up, and an Addresses key containing an +array of IPv4 and/or IPv6 addresses as strings. Looking up an address for +a name will cause prefix information for all addresses found to be cached, +as well.

  • +
+ + +

All JSON resources also contain a Cached key, the time at which the data +entry was put into the cache in +[RFC3339][https://datatracker.ietf.org/doc/RFC3339] format.

+ +

BACKENDS

+ +

The prefix.json resource currently uses the Prefix Overview and Geolocation +API entry points from [RIPEstat][https://stat.ripe.net].

+ +

The address.json resource uses DNS, as provided by the Go standard library's +net.LookupIP() (i.e., the system resolver)

+ +

AUTHOR

+ +

Brian Trammell brian@trammell.ch

+ +

LICENSE

+ +

Copyright (c) 2016 - 2018 Brian Trammell

+ +

Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions:

+ +

The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software.

+ +

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE.

+ + +
    +
  1. +
  2. February 2018
  3. +
  4. canid(1)
  5. +
+ +
+ + diff -pruN 0.0~git20170120.15a8ca0-1/doc/canid.1.md 0.0~git20180613.007c9af-1/doc/canid.1.md --- 0.0~git20170120.15a8ca0-1/doc/canid.1.md 1970-01-01 00:00:00.000000000 +0000 +++ 0.0~git20180613.007c9af-1/doc/canid.1.md 2018-02-09 22:03:00.000000000 +0000 @@ -0,0 +1,94 @@ +# canid(1) -- the caching additional network information daemon + +## SYNOPSIS + +`canid` [-file ] [-expiry ] [-concurrency ] [-port ] + +## DESCRIPTION + +Canid provides a simple web service for caching and simplifying information +retrieved from other services (see [BACKENDS][]) about Internet hostnames and +IP addresses. It is designed for use when looking up many addresses and/ + +On launch, Canid begins serving on the specified port. It shuts down cleanly +on SIGINT (^C on the console). + +## OPTIONS + + * `-file` (default: no backing store) + Use the given JSON file as a backing store for the cache. + Loads the cache from this file on startup, and saves it on termination. + + * `-expiry` (default: 86400, 1 day) + Expire cache entries after seconds. + + * `-concurrency` (default: 16) + Allow at most simultaneous pending requests per backend. + + * `-port` (default: 8043) + TCP port to listen on + +## RESOURCES + +Canid provides three resources via HTTP: + + * `/` + + The root resource is an HTML page providing a simple web + front-end to the service. + + * `/prefix.json?addr=` + + Look up information about the prefix associated with an address, and + return it as a JSON object. This object presently contains a `Prefix` key + with the routed prefix associated with the address, an `ASN` key with a + BGP autonomous system number associated with the address, and a + `CountryCode` key for an ISO 3166 country code associated with the + address. + + * `/address.json?name=` + + Look up an Internet hostname via DNS, and return the IPv4 and IPv6 + addresses associated with it as a JSON object. This object contains a + `Name` key with the name looked up, and an `Addresses` key containing an + array of IPv4 and/or IPv6 addresses as strings. Looking up an address for + a name will cause prefix information for all addresses found to be cached, + as well. + +All JSON resources also contain a `Cached` key, the time at which the data +entry was put into the cache in +[RFC3339][https://datatracker.ietf.org/doc/RFC3339] format. + +## BACKENDS + +The `prefix.json` resource currently uses the Prefix Overview and Geolocation +API entry points from [RIPEstat][https://stat.ripe.net]. + +The `address.json` resource uses DNS, as provided by the Go standard library's +`net.LookupIP()` (i.e., the system resolver) + +## AUTHOR + +Brian Trammell + +## LICENSE + +Copyright (c) 2016 - 2018 Brian Trammell + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff -pruN 0.0~git20170120.15a8ca0-1/prefixcache.go 0.0~git20180613.007c9af-1/prefixcache.go --- 0.0~git20170120.15a8ca0-1/prefixcache.go 2018-01-24 11:31:14.000000000 +0000 +++ 0.0~git20180613.007c9af-1/prefixcache.go 2018-02-09 22:03:00.000000000 +0000 @@ -97,7 +97,7 @@ func (cache *PrefixCache) LookupServer(w prefix_info, err := cache.Lookup(ip) if err != nil { - w.WriteHeader(http.StatusInternalServerError) + w.WriteHeader(http.StatusInternalServerError) // FIXME not always a 500 error_struct := struct{ Error string }{err.Error()} error_body, _ := json.Marshal(error_struct) w.Write(error_body) diff -pruN 0.0~git20170120.15a8ca0-1/README.md 0.0~git20180613.007c9af-1/README.md --- 0.0~git20170120.15a8ca0-1/README.md 2018-01-24 11:31:14.000000000 +0000 +++ 0.0~git20180613.007c9af-1/README.md 2018-02-09 22:03:00.000000000 +0000 @@ -1,28 +1,78 @@ -# canid +# canid(1) -- the caching additional network information daemon -the Caching Additional Network Information Daemon provides a simple HTTP API for getting information about Internet names and numbers from a given vantage point. +## SYNOPSIS -canid has two entry points: +`canid` [-file _<cachefile>_] [-expiry _<sec>_] [-concurrency _<n>_] [-port _<port>_] -- `/prefix.json?addr=` looks up BGP AS number and country code associated with the smallest prefix announced which contains the address in the RIPEstat database. It caches the results by prefix in memory. It returns a JSON object with four keys: - - Prefix: CIDR-notation prefix associated with the address - - ASN: First AS number associated with the prefix by RIPEstat - - CountryCode: First country code associated with the prefix by RIPEstat - - Cached: Timestamp at which the result was cached from RIPEstat +## DESCRIPTION -- `/addresses.json?name=` looks up the IPv4 and IPv6 addresses associated with a given name. It caches the results by name in memory, and precaches prefix results for a subsequent prefix call. It returns a JSON object with three keys: - - Name: the name looked up - - Addresses: array of IP addresses associated with the name, as a string - - Cached: Timestamp at which the result was cached from DNS +Canid provides a simple web service for caching and simplifying information +retrieved from other services (see [BACKENDS][]) about Internet hostnames and +IP addresses. It is designed for use when looking up many addresses and/ -To install: +On launch, Canid begins serving on the specified port. It shuts down cleanly +on SIGINT (^C on the console). + +## INSTALLING ``` $ go install github.com/britram/canid/canid ``` -For usage: +## OPTIONS -``` -$ canid -help -``` \ No newline at end of file + * `-file` _<cachefile>_ (default: no backing store) + Use the given JSON file as a backing store for the cache. + Loads the cache from this file on startup, and saves it on termination. + + * `-expiry` _<sec>_ (default: 86400, 1 day) + Expire cache entries after _<sec>_ seconds. + + * `-concurrency` _<n>_ (default: 16) + Allow at most _<n>_ simultaneous pending requests per backend. + + * `-port` _<port>_ (default: 8043) + TCP port to listen on + +## RESOURCES + +Canid provides three resources via HTTP: + + * `/` + + The root resource is an HTML page providing a simple web + front-end to the service. + + * `/prefix.json?addr=` + + Look up information about the prefix associated with an address, and + return it as a JSON object. This object presently contains a `Prefix` key + with the routed prefix associated with the address, an `ASN` key with a + BGP autonomous system number associated with the address, and a + `CountryCode` key for an ISO 3166 country code associated with the + address. + + * `/address.json?name=` + + Look up an Internet hostname via DNS, and return the IPv4 and IPv6 + addresses associated with it as a JSON object. This object contains a + `Name` key with the name looked up, and an `Addresses` key containing an + array of IPv4 and/or IPv6 addresses as strings. Looking up an address for + a name will cause prefix information for all addresses found to be cached, + as well. + +All JSON resources also contain a `Cached` key, the time at which the data +entry was put into the cache in +[RFC3339][https://datatracker.ietf.org/doc/RFC3339] format. + +## BACKENDS + +The `prefix.json` resource currently uses the Prefix Overview and Geolocation +API entry points from [RIPEstat][https://stat.ripe.net]. + +The `address.json` resource uses DNS, as provided by the Go standard library's +`net.LookupIP()` (i.e., the system resolver) + +## AUTHOR + +Brian Trammell _<brian@trammell.ch>_