Use ooni/probe-engine: episode 1 (#42)

This commit is contained in:
Simone Basso 2019-05-23 16:38:46 +02:00 committed by GitHub
parent eb4fec2f21
commit df629237be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 147 additions and 322 deletions

6
go.mod
View File

@ -16,13 +16,11 @@ require (
github.com/mattn/go-colorable v0.0.9
github.com/mattn/go-isatty v0.0.7 // indirect
github.com/mattn/go-sqlite3 v1.10.0 // indirect
github.com/measurement-kit/go-measurement-kit v0.0.0-20190509222408-0d0cd3233336
github.com/oschwald/geoip2-golang v1.2.1
github.com/oschwald/maxminddb-golang v1.3.0 // indirect
github.com/measurement-kit/go-measurement-kit v0.0.0-20190521082856-635e836bbb9d
github.com/ooni/probe-engine v0.0.0-20190522105151-0c60545f09ea
github.com/pkg/errors v0.8.1
github.com/rubenv/sql-migrate v0.0.0-20190327083759-54bad0a9b051
github.com/ziutek/mymysql v1.5.4 // indirect
golang.org/x/sys v0.0.0-20190509141414-a5b02f93d862 // indirect
google.golang.org/appengine v1.5.0 // indirect
gopkg.in/AlecAivazis/survey.v1 v1.8.4
gopkg.in/gorp.v1 v1.7.2 // indirect

90
go.sum
View File

@ -1,5 +1,17 @@
github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8=
github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8 h1:xzYJEypr/85nBpB11F9br+3HUrpgb+fcm5iADzXXYEw=
github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8/go.mod h1:oX5x61PbNXchhh0oikYAH+4Pcfw5LKv21+Jnpr6r6Pc=
github.com/Psiphon-Inc/rotate-safe-writer v0.0.0-20170228160301-b276127301a9/go.mod h1:ZdY5pBfat/WVzw3eXbIf7N1nZN0XD5H5+X8ZMDWbCs4=
github.com/Psiphon-Labs/bolt v0.0.0-20170814173724-c6e046a80d4b/go.mod h1:nYj8s6HxsjYV7vZjTiH3tMcVjj/x+R702DXT89PomgE=
github.com/Psiphon-Labs/dns v0.0.0-20170814182607-d23cdaf67bbc/go.mod h1:F1eU0RdWZXN2kn6A8cBRixr1HLyM1Va7xXp88LRhlps=
github.com/Psiphon-Labs/goarista v0.0.0-20160825065156-d002785f4c67/go.mod h1:5Jm7sRmp4HSWIoZk/ZRryF/KbcQeIhBMoaGqD7psbkU=
github.com/Psiphon-Labs/goptlib v0.0.0-20180426172440-18963be5f9c5/go.mod h1:Pe5BqN2DdIdChorAXl6bDaQd/wghpCleJfid2NoSli0=
github.com/Psiphon-Labs/net v0.0.0-20180912164743-03e6572170e3/go.mod h1:hEyxqKp/oea6zboy3de4ADnM2rpTjY5QslIvMQb2Zrk=
github.com/Psiphon-Labs/psiphon-tunnel-core v2.0.2+incompatible/go.mod h1:VcNEtiQ0z2sCGJf16ZGcpwCas5+r9rt+P20r6LlJ06U=
github.com/Psiphon-Labs/tls-tris v0.0.0-20190321174524-b5083341bf6c/go.mod h1:v3y9GXFo9Sf2mO6auD2ExGG7oDgrK8TI7eb49ZnUxrE=
github.com/Psiphon-Labs/utls v0.0.0-20181219022742-11a4cc033322/go.mod h1:PpQnNy4saPoubINWgzxoSAvOHmNaeifjBJod1ut0UpI=
github.com/Yawning/chacha20 v0.0.0-20170904085104-e3b1f968fc63/go.mod h1:nf+Komq6fVP4SwmKEaVGxHTyQGKREVlwjQKpvOV39yE=
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0XSf3YxCJs6N6AOSrOx3obionmG7T0y0=
github.com/alecthomas/kingpin v2.2.6+incompatible h1:5svnBTFgJjZvGKyYBtMB0+m5wvrbUHiqye8wRJMlnYI=
github.com/alecthomas/kingpin v2.2.6+incompatible/go.mod h1:59OFYbFVLKQKq+mqrL6Rw5bR0c3ACQaawgXx0QYndlE=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc h1:cAKDfWh5VpdgMhJosfJnn5/FoN2SRZ4p7fJNX58YPaU=
@ -8,14 +20,28 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZq
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/apex/log v1.1.0 h1:J5rld6WVFi6NxA6m8GJ1LJqu3+GiTFIt3mYv27gdQWI=
github.com/apex/log v1.1.0/go.mod h1:yA770aXIDQrhVOIGurT/pVdfCpSq1GQV/auzMN5fzvY=
github.com/aristanetworks/goarista v0.0.0-20190514202536-8f808a500156/go.mod h1:D/tb0zPVXnP7fmsLZjtdUhSsumbK/ij54UXjjVgMGxQ=
github.com/armon/go-proxyproto v0.0.0-20190211145416-68259f75880e/go.mod h1:QmP9hvJ91BbJmGVGSbutW19IC0Q9phDCLGaomwTJbgU=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/bifurcation/mint v0.0.0-20180715133206-93c51c6ce115/go.mod h1:zVt7zX3K/aDCk9Tj+VM7YymsX66ERvzCJzw8rFCX2JU=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/certifi/gocertifi v0.0.0-20180118203423-deb3ae2ef261 h1:6/yVvBsKeAw05IUj4AzvrxaCnDjN4nUqKjW9+w5wixg=
github.com/certifi/gocertifi v0.0.0-20180118203423-deb3ae2ef261/go.mod h1:GJKEexRPVJrBSOjoqN5VNOIKJ5Q3RViH6eu3puDRwx4=
github.com/cheekybits/genny v0.0.0-20170328200008-9127e812e1e9/go.mod h1:+tQajlRqAUrPI7DOSpB0XAqZYtQakVtB7wXkRAgjxjQ=
github.com/creack/goselect v0.1.0/go.mod h1:gHrIcH/9UZDn2qgeTUeW5K9eZsVYCH6/60J/FHysWyE=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deckarep/golang-set v1.7.1/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ=
github.com/dgraph-io/badger v1.5.4/go.mod h1:VZxzAIRPHRVNRKRo6AXrX9BJegn6il06VMTZVJYCIjQ=
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/elazarl/goproxy v0.0.0-20190421051319-9d40249d3c2f/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
github.com/elazarl/goproxy/ext v0.0.0-20190421051319-9d40249d3c2f/go.mod h1:gNh8nYJoAm43RfaxurUnxr+N1PwuFV3ZMl/efxlIlY8=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/getsentry/raven-go v0.0.0-20190419175539-919484f041ea h1:vpAHg3H71YFc5TqRSqbhMq8Wd0kdPoQMMAeQSgnUTpg=
github.com/getsentry/raven-go v0.0.0-20190419175539-919484f041ea/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ=
github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA=
@ -42,12 +68,23 @@ github.com/gobuffalo/packr/v2 v2.0.9/go.mod h1:emmyGweYTm6Kdper+iywB6YK5YzuKchGt
github.com/gobuffalo/packr/v2 v2.1.0/go.mod h1:n90ZuXIc2KN2vFAOQascnPItp9A2g9QYSvYvS3AjQEM=
github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754 h1:tpom+2CJmpzAWj5/VEHync2rJGi+epHNIeRSWjzGA+4=
github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw=
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/gxui v0.0.0-20151028112939-f85e0a97b3a4/go.mod h1:Pw1H1OjSNHiqeuxAduB1BKYXIwFtsyrY47nEqSgEiCM=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/grafov/m3u8 v0.6.1/go.mod h1:PdjzaU/pJUo4jTIn2rcgMFs+HqBGl/sPJLr8BI0Xq/I=
github.com/hashicorp/golang-lru v0.0.0-20180201235237-0fb14efe8c47/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174 h1:WlZsjVhE8Af9IcZDGgJGQpNflI3+MJSBhsgT5PCtzBQ=
github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174/go.mod h1:DqJ97dSdRW1W22yXSB90986pcOyQ7r45iio1KN2ez1A=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/juju/ratelimit v1.0.1/go.mod h1:qapgC/Gy+xNh9UxzV13HGGl/6UXNN+ct+vwSgWNm/qk=
github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
@ -60,8 +97,15 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lib/pq v1.1.1 h1:sJZmqHoEaY7f+NPP8pgLB/WxulyR3fewgCM2qaSlBb4=
github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lucas-clemente/aes12 v0.0.0-20171027163421-cd47fb39b79f/go.mod h1:JpH9J1c9oX6otFSgdUHwUBUizmKlrMjxWnIAjff4m04=
github.com/lucas-clemente/quic-clients v0.1.0/go.mod h1:y5xVIEoObKqULIKivu+gD/LU90pL73bTdtQjPBvtCBk=
github.com/lucas-clemente/quic-go v0.10.2/go.mod h1:hvaRS9IHjFLMq76puFJeWNfmn+H70QZ/CXoxqw9bzao=
github.com/lucas-clemente/quic-go-certificates v0.0.0-20160823095156-d2f86524cced/go.mod h1:NCcRLrOTZbzhZvixZLlERbJtDtYsmMw8Jc4vS8Z0g58=
github.com/m-lab/ndt7-client-go v0.0.0-20190516113520-f8aec6e1ef2e/go.mod h1:nD9WTkxP4/mV2ph5uUpVPD2ZOJdZ9QKPTKu3tJGkM9o=
github.com/markbates/oncer v0.0.0-20181203154359-bf2de49a0be2/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE=
github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0=
github.com/marten-seemann/qtls v0.2.3/go.mod h1:xzjG7avBwGGbdZ8dTGxlBnLArsVKLvwmjgmPuiQEcYk=
github.com/marusama/semaphore v0.0.0-20190110074507-6952cef993b2/go.mod h1:TmeOqAKoDinfPfSohs14CO3VcEf7o+Bem6JiNe05yrQ=
github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
@ -69,27 +113,44 @@ github.com/mattn/go-isatty v0.0.7 h1:UvyT9uN+3r7yLEYSlJsbQGdsaB/a0DlgWP3pql6iwOc
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-sqlite3 v1.10.0 h1:jbhqpg7tQe4SupckyijYiy0mJJ/pRyHvXf7JdWK860o=
github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/measurement-kit/go-measurement-kit v0.0.0-20190509222408-0d0cd3233336 h1:V68g+e6YpllWozgpR40rfLFWWS7iHDDy1UJj4IbiDcw=
github.com/measurement-kit/go-measurement-kit v0.0.0-20190509222408-0d0cd3233336/go.mod h1:U+1073kDD7WgZrs+F9fKgFVWXikYAB7LZAWOd7CMHyQ=
github.com/measurement-kit/go-measurement-kit v0.0.0-20190521082856-635e836bbb9d h1:w8l3iUS/zDNcNQwios6icSyH3qXrDE+D6k1kSob0RnU=
github.com/measurement-kit/go-measurement-kit v0.0.0-20190521082856-635e836bbb9d/go.mod h1:n4Mki43BUXopDPfUkgry9vmSzwZ7dVL5Mx5mRUCWKEw=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/oschwald/geoip2-golang v1.2.1 h1:3iz+jmeJc6fuCyWeKgtXSXu7+zvkxJbHFXkMT5FVebU=
github.com/oschwald/geoip2-golang v1.2.1/go.mod h1:0LTTzix/Ao1uMvOhAV4iLU0Lz7eCrP94qZWBTDKf0iE=
github.com/miekg/dns v1.1.12/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/ooni/probe-engine v0.0.0-20190522105151-0c60545f09ea h1:Dx1uyp66YkHDR42r66cA1GlCp4y5hF2fuW+apL9/oV0=
github.com/ooni/probe-engine v0.0.0-20190522105151-0c60545f09ea/go.mod h1:o6RJkZwHVn6GP7xMLVdRsd4pOxXeo1tJKK29TKKiRhA=
github.com/oschwald/geoip2-golang v1.3.0 h1:D+Hsdos1NARPbzZ2aInUHZL+dApIzo8E0ErJVsWcku8=
github.com/oschwald/geoip2-golang v1.3.0/go.mod h1:0LTTzix/Ao1uMvOhAV4iLU0Lz7eCrP94qZWBTDKf0iE=
github.com/oschwald/maxminddb-golang v1.3.0 h1:oTh8IBSj10S5JNlUDg5WjJ1QdBMdeaZIkPEVfESSWgE=
github.com/oschwald/maxminddb-golang v1.3.0/go.mod h1:3jhIUymTJ5VREKyIhWm66LJiQt04F0UCDdodShpjWsY=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/pborman/getopt v0.0.0-20190409184431-ee0cd42419d3/go.mod h1:85jBQOZwpVEaDAr341tbn15RS4fCAsIst0qp7i8ex1o=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/redjack/marionette v0.0.0-20180930054334-5d0d25fc4084/go.mod h1:yJd0pT0e04p+VSmLGjce8BoPlRDlrGrdfXf2En7oq9A=
github.com/refraction-networking/utls v0.0.0-20190415193640-32987941ebd3/go.mod h1:tz9gX959MEFfFN5whTIocCLUG57WiILqtdVxI8c6Wj0=
github.com/rogpeppe/go-charset v0.0.0-20180617210344-2471d30d28b4/go.mod h1:qgYeAmZ5ZIpBWTGllZSQnw97Dj+woV0toclVaRGI8pc=
github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.3.0 h1:RR9dF3JtopPvtkroDZuVD7qquD0bnHlKSqaQhgwt8yk=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rubenv/sql-migrate v0.0.0-20190327083759-54bad0a9b051 h1:p32bQkgLiadYiOqs294BAx/7f1Aerfva8rj+rVvzR0A=
github.com/rubenv/sql-migrate v0.0.0-20190327083759-54bad0a9b051/go.mod h1:WS0rl9eEliYI8DPnr3TOwz4439pay+qNgzJoVya/DmY=
github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
github.com/sergeyfrolov/bsbuffer v0.0.0-20180903213811-94e85abb8507/go.mod h1:DbI1gxrXI2jRGw7XGEUZQOOMd6PsnKzRrCKabvvMrwM=
github.com/sergeyfrolov/gotapdance v0.0.0-20190321212638-ca457d7d62c3/go.mod h1:iQJhqHl49y9CULep5DOD+0W5dKgky8GQOioe3pUd/FY=
github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
@ -99,34 +160,51 @@ github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
github.com/zach-klippenstein/goregen v0.0.0-20160303162051-795b5e3961ea/go.mod h1:eNr558nEUjP8acGw8FFjTeWvSgU1stO7FAO6eknhHe4=
github.com/ziutek/mymysql v1.5.4 h1:GB0qdRGsTwQSBVYuVShFBKaXSnSnYYC2d9knnE1LHFs=
github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190123085648-057139ce5d2b h1:Elez2XeF2p9uyVj0yEUDqQ56NFcDtcBNkYP7yv8YbUE=
golang.org/x/crypto v0.0.0-20190123085648-057139ce5d2b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190509222800-a4d6f7feada5/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190412183630-56d357773e84/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180606202747-9527bec2660b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190509141414-a5b02f93d862 h1:rM0ROo5vb9AdYJi1110yjWGMej9ITfKddS89P3Fkhug=
golang.org/x/sys v0.0.0-20190509141414-a5b02f93d862/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190228124157-a34e9553db1e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190516110030-61b9204099cb h1:k07iPOt0d6nEnwXF+kHB+iEg+WSuKe/SOQuFM2QoD+E=
golang.org/x/sys v0.0.0-20190516110030-61b9204099cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190329151228-23e29df326fe/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190404132500-923d25813098/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
google.golang.org/appengine v1.5.0 h1:KxkO13IPW4Lslp2bz+KHP2E3gtFlrIGNThxkZQ3g+4c=
google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
gopkg.in/AlecAivazis/survey.v1 v1.8.4 h1:10xXXN3wgIhPheb5NI58zFgZv32Ana7P3Tl4shW+0Qc=
gopkg.in/AlecAivazis/survey.v1 v1.8.4/go.mod h1:iBNOmqKz/NUbZx3bA+4hAGLRC7fSK7tgtVDT4tB22XA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/gorp.v1 v1.7.2 h1:j3DWlAyGVv8whO7AcIWznQ2Yj7yJkn34B8s63GViAAw=
gopkg.in/gorp.v1 v1.7.2/go.mod h1:Wo3h+DBQZIxATwftsglhdD/62zRFPhGhTiu5jUJmCaw=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
upper.io/db.v3 v3.5.7+incompatible h1:3MJSnJQ+NMxBxuNwO+gOKFiugwv+f61LbyuZYSPzoi4=
upper.io/db.v3 v3.5.7+incompatible/go.mod h1:FgTdD24eBjJAbPKsQSiHUNgXjOR4Lub3u1UMHSIh82Y=

View File

@ -4,13 +4,13 @@ import (
"os"
"github.com/apex/log"
ooni "github.com/ooni/probe-cli"
"github.com/ooni/probe-cli/internal/cli/root"
"github.com/ooni/probe-cli/version"
)
// Run the app. This is the main app entry point
func Run() {
root.Cmd.Version(ooni.Version)
root.Cmd.Version(version.Version)
_, err := root.Cmd.Parse(os.Args[1:])
if err != nil {
log.WithError(err).Error("failure in main command")

View File

@ -1,20 +1,15 @@
package geoip
import (
"fmt"
"github.com/alecthomas/kingpin"
"github.com/apex/log"
"github.com/ooni/probe-cli/internal/cli/root"
"github.com/ooni/probe-cli/internal/output"
"github.com/ooni/probe-cli/utils"
)
func init() {
cmd := root.Command("geoip", "Perform a geoip lookup")
shouldUpdate := cmd.Flag("update", "Update the geoip database").Bool()
cmd.Action(func(_ *kingpin.ParseContext) error {
output.SectionTitle("GeoIP lookup")
ctx, err := root.Init()
@ -22,26 +17,17 @@ func init() {
return err
}
if err = ctx.MaybeDownloadDataFiles(); err != nil {
log.WithError(err).Error("failed to download data files")
}
geoipPath := utils.GeoIPDir(ctx.Home)
if *shouldUpdate {
utils.DownloadGeoIPDatabaseFiles(geoipPath)
}
loc, err := utils.GeoIPLookup(geoipPath)
err = ctx.MaybeLocationLookup()
if err != nil {
return err
}
log.WithFields(log.Fields{
"type": "table",
"asn": fmt.Sprintf("AS%d", loc.ASN),
"network_name": loc.NetworkName,
"country_code": loc.CountryCode,
"ip": loc.IP,
"asn": ctx.Session.ProbeASNString(),
"network_name": ctx.Session.ProbeNetworkName(),
"country_code": ctx.Session.ProbeCC(),
"ip": ctx.Session.ProbeIP(),
}).Info("Looked up your location")
return nil

View File

@ -7,6 +7,7 @@ import (
"github.com/ooni/probe-cli/internal/log/handlers/batch"
"github.com/ooni/probe-cli/internal/log/handlers/cli"
"github.com/ooni/probe-cli/utils"
"github.com/ooni/probe-cli/version"
)
// Cmd is the root command
@ -32,7 +33,7 @@ func init() {
}
if *isVerbose {
log.SetLevel(log.DebugLevel)
log.Debugf("ooni version %s", ooni.Version)
log.Debugf("ooni version %s", version.Version)
}
Init = func() (*ooni.Context, error) {

View File

@ -82,15 +82,15 @@ func init() {
if *bouncerURL != "" {
ctx.Config.Advanced.BouncerURL = *bouncerURL
}
log.Debugf("Using collector %s", ctx.Config.Advanced.CollectorURL)
log.Debugf("Using bouncer %s", ctx.Config.Advanced.CollectorURL)
log.Debugf("Using collector: %s", ctx.Config.Advanced.CollectorURL)
log.Debugf("Using bouncer: %s", ctx.Config.Advanced.CollectorURL)
err = ctx.MaybeLocationLookup()
if err != nil {
log.WithError(err).Error("Failed to lookup the location of the probe")
return err
}
network, err := database.CreateNetwork(ctx.DB, ctx.Location)
network, err := database.CreateNetwork(ctx.DB, ctx.Session.Location)
if err != nil {
log.WithError(err).Error("Failed to create the network row")
return err

View File

@ -4,15 +4,15 @@ import (
"fmt"
"github.com/alecthomas/kingpin"
ooni "github.com/ooni/probe-cli"
"github.com/ooni/probe-cli/internal/cli/root"
"github.com/ooni/probe-cli/version"
)
func init() {
cmd := root.Command("version", "Show version.")
cmd.Action(func(_ *kingpin.ParseContext) error {
fmt.Println(ooni.Version)
fmt.Println(version.Version)
return nil
})
}

View File

@ -8,6 +8,7 @@ import (
"time"
"github.com/apex/log"
"github.com/ooni/probe-engine/model"
"github.com/ooni/probe-cli/utils"
"github.com/pkg/errors"
db "upper.io/db.v3"
@ -193,14 +194,14 @@ func CreateResult(sess sqlbuilder.Database, homePath string, testGroupName strin
}
// CreateNetwork will create a new network in the network table
func CreateNetwork(sess sqlbuilder.Database, location *utils.LocationInfo) (*Network, error) {
func CreateNetwork(sess sqlbuilder.Database, location *model.LocationInfo) (*Network, error) {
network := Network{
ASN: location.ASN,
CountryCode: location.CountryCode,
NetworkName: location.NetworkName,
// On desktop we consider it to always be wifi
NetworkType: "wifi",
IP: location.IP,
IP: location.ProbeIP,
}
newID, err := sess.Collection("networks").Insert(network)
if err != nil {

View File

@ -7,7 +7,7 @@ import (
"os"
"testing"
"github.com/ooni/probe-cli/utils"
"github.com/ooni/probe-engine/model"
db "upper.io/db.v3"
)
@ -29,7 +29,7 @@ func TestMeasurementWorkflow(t *testing.T) {
t.Fatal(err)
}
location := utils.LocationInfo{
location := model.LocationInfo{
ASN: 0,
CountryCode: "IT",
NetworkName: "Unknown",
@ -103,7 +103,7 @@ func TestDeleteResult(t *testing.T) {
t.Fatal(err)
}
location := utils.LocationInfo{
location := model.LocationInfo{
ASN: 0,
CountryCode: "IT",
NetworkName: "Unknown",
@ -175,13 +175,13 @@ func TestNetworkCreate(t *testing.T) {
t.Fatal(err)
}
l1 := utils.LocationInfo{
l1 := model.LocationInfo{
ASN: 2,
CountryCode: "IT",
NetworkName: "Antaninet",
}
l2 := utils.LocationInfo{
l2 := model.LocationInfo{
ASN: 3,
CountryCode: "IT",
NetworkName: "Fufnet",

View File

@ -4,7 +4,6 @@ import (
"database/sql"
"encoding/json"
"fmt"
"os"
"path/filepath"
"time"
@ -17,6 +16,7 @@ import (
"github.com/ooni/probe-cli/internal/output"
"github.com/ooni/probe-cli/utils"
"github.com/ooni/probe-cli/utils/strcase"
"github.com/ooni/probe-cli/version"
)
// Nettest interface. Every Nettest should implement this.
@ -70,7 +70,10 @@ func (c *Controller) SetNettestIndex(i, n int) {
// Init should be called once to initialise the nettest
func (c *Controller) Init(nt *mk.Nettest) error {
log.Debugf("Init: %v", nt)
c.Ctx.LocationLookup()
err := c.Ctx.MaybeLocationLookup()
if err != nil {
return err
}
c.msmts = make(map[int64]*database.Measurement)
@ -79,8 +82,8 @@ func (c *Controller) Init(nt *mk.Nettest) error {
testName := strcase.ToSnake(nt.Name)
resultID := c.res.ID
reportFilePath := c.msmtPath
geoIPCountryPath := filepath.Join(utils.GeoIPDir(c.Ctx.Home), "GeoLite2-Country.mmdb")
geoIPASNPath := filepath.Join(utils.GeoIPDir(c.Ctx.Home), "GeoLite2-ASN.mmdb")
geoIPCountryPath := c.Ctx.Session.CountryDatabasePath()
geoIPASNPath := c.Ctx.Session.ASNDatabasePath()
msmtPath := c.msmtPath
log.Debugf("OutputPath: %s", msmtPath)
@ -90,26 +93,22 @@ func (c *Controller) Init(nt *mk.Nettest) error {
IncludeCountry: c.Ctx.Config.Sharing.IncludeCountry,
LogLevel: "INFO",
ProbeCC: c.Ctx.Location.CountryCode,
ProbeASN: fmt.Sprintf("AS%d", c.Ctx.Location.ASN),
ProbeIP: c.Ctx.Location.IP,
ProbeCC: c.Ctx.Session.ProbeCC(),
ProbeASN: c.Ctx.Session.ProbeASNString(),
ProbeIP: c.Ctx.Session.ProbeIP(),
DisableReportFile: false,
DisableCollector: !c.Ctx.Config.Sharing.UploadResults,
RandomizeInput: false, // It's important to disable input randomization to ensure the URLs are written in sync to the DB
SoftwareName: "ooniprobe-desktop",
SoftwareVersion: ooni.Version,
SoftwareVersion: version.Version,
CollectorBaseURL: c.Ctx.Config.Advanced.CollectorURL,
BouncerBaseURL: c.Ctx.Config.Advanced.BouncerURL,
OutputPath: msmtPath,
GeoIPCountryPath: geoIPCountryPath,
GeoIPASNPath: geoIPASNPath,
}
sslCertFile := os.Getenv("SSL_CERT_FILE")
if sslCertFile != "" {
nt.Options.CaBundlePath = sslCertFile
CaBundlePath: c.Ctx.Session.CABundlePath(),
}
log.Debugf("CaBundlePath: %s", nt.Options.CaBundlePath)

View File

@ -37,7 +37,7 @@ func lookupURLs(ctl *nettests.Controller) ([]string, map[int64]int64, error) {
// XXX pass in the configuration for category codes
reqURL := fmt.Sprintf("%s/api/v1/urls?probe_cc=%s",
orchestrateBaseURL,
ctl.Ctx.Location.CountryCode)
ctl.Ctx.Session.ProbeCC())
resp, err := http.Get(reqURL)
if err != nil {

50
ooni.go
View File

@ -1,9 +1,9 @@
package ooni
import (
"context"
"io/ioutil"
"os"
"path"
"github.com/apex/log"
"github.com/ooni/probe-cli/config"
@ -12,18 +12,18 @@ import (
"github.com/ooni/probe-cli/internal/legacy"
"github.com/ooni/probe-cli/internal/onboard"
"github.com/ooni/probe-cli/utils"
"github.com/ooni/probe-cli/version"
"github.com/ooni/probe-engine/session"
"github.com/pkg/errors"
"upper.io/db.v3/lib/sqlbuilder"
)
const Version = "3.0.0-beta.3"
// Context for OONI Probe
type Context struct {
Config *config.Config
DB sqlbuilder.Database
Location *utils.LocationInfo
IsBatch bool
Session *session.Session
Home string
TempDir string
@ -34,27 +34,7 @@ type Context struct {
// MaybeLocationLookup will lookup the location of the user unless it's already cached
func (c *Context) MaybeLocationLookup() error {
if c.Location == nil {
return c.LocationLookup()
}
return nil
}
// LocationLookup lookup the location of the user via geoip
func (c *Context) LocationLookup() error {
var err error
if err = c.MaybeDownloadDataFiles(); err != nil {
log.WithError(err).Error("failed to download data files")
}
geoipDir := utils.GeoIPDir(c.Home)
c.Location, err = utils.GeoIPLookup(geoipDir)
if err != nil {
return err
}
return nil
return c.Session.LookupLocation(context.Background())
}
// MaybeOnboarding will run the onboarding process only if the informed consent
@ -71,18 +51,6 @@ func (c *Context) MaybeOnboarding() error {
return nil
}
// MaybeDownloadDataFiles will download geoip data files if they are not present
func (c *Context) MaybeDownloadDataFiles() error {
geoipDir := utils.GeoIPDir(c.Home)
if _, err := os.Stat(path.Join(geoipDir, "GeoLite2-Country.mmdb")); os.IsNotExist(err) {
log.Debugf("Downloading GeoIP database files")
if err := utils.DownloadGeoIPDatabaseFiles(geoipDir); err != nil {
return err
}
}
return nil
}
// Init the OONI manager
func (c *Context) Init() error {
var err error
@ -123,12 +91,18 @@ func (c *Context) Init() error {
return nil
}
// NewContext instance.
// NewContext creates a new context instance.
func NewContext(configPath string, homePath string) *Context {
return &Context{
Home: homePath,
Config: &config.Config{},
configPath: configPath,
Session: session.New(
log.Log,
"ooniprobe-desktop",
version.Version,
utils.AssetsDir(homePath),
),
}
}

View File

@ -1,222 +0,0 @@
package utils
import (
"archive/tar"
"compress/gzip"
"encoding/json"
"io"
"io/ioutil"
"math/rand"
"net"
"net/http"
"os"
"path/filepath"
"time"
"github.com/oschwald/geoip2-golang"
"github.com/pkg/errors"
)
// LocationInfo contains location information
type LocationInfo struct {
IP string
ASN uint
NetworkName string
CountryCode string
}
// XXX consider integration with: https://updates.maxmind.com/app/update_getfilename?product_id=GeoLite2-ASN
var geoipFiles = map[string]string{
"GeoLite2-ASN.mmdb": "http://geolite.maxmind.com/download/geoip/database/GeoLite2-ASN.tar.gz",
"GeoLite2-Country.mmdb": "http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.tar.gz",
}
// Download the file to a temporary location
func downloadToTemp(url string) (string, error) {
out, err := ioutil.TempFile(os.TempDir(), "maxmind")
if err != nil {
return "", errors.Wrap(err, "failed to create temporary directory")
}
resp, err := http.Get(url)
if err != nil {
return "", errors.Wrap(err, "failed to fetch URL")
}
_, err = io.Copy(out, resp.Body)
if err != nil {
return "", errors.Wrap(err, "failed to copy response body")
}
out.Close()
resp.Body.Close()
return out.Name(), nil
}
// DownloadGeoIPDatabaseFiles into the target directory
func DownloadGeoIPDatabaseFiles(dir string) error {
for filename, url := range geoipFiles {
dstPath := filepath.Join(dir, filename)
tmpPath, err := downloadToTemp(url)
if err != nil {
return err
}
// Extract the tar.gz file
f, err := os.Open(tmpPath)
if err != nil {
return errors.Wrap(err, "failed to read file")
}
gzf, err := gzip.NewReader(f)
if err != nil {
return errors.Wrap(err, "failed to create gzip reader")
}
tarReader := tar.NewReader(gzf)
// Look inside of the tar for the file we need
for {
header, err := tarReader.Next()
if err == io.EOF {
break
}
if err != nil {
return errors.Wrap(err, "error extracting tar.gz")
}
name := header.Name
if filepath.Base(name) == filename {
outFile, err := os.Create(dstPath)
if err != nil {
return errors.Wrap(err, "error creating file")
}
if _, err := io.Copy(outFile, tarReader); err != nil {
return errors.Wrap(err, "error reading file from tar")
}
outFile.Close()
break
}
}
f.Close()
}
return nil
}
// LookupLocation resolves an IP to a location according to the Maxmind DB
func LookupLocation(dbPath string, ipStr string) (LocationInfo, error) {
loc := LocationInfo{IP: ipStr}
asnDB, err := geoip2.Open(filepath.Join(dbPath, "GeoLite2-ASN.mmdb"))
if err != nil {
return loc, errors.Wrap(err, "failed to open ASN db")
}
defer asnDB.Close()
countryDB, err := geoip2.Open(filepath.Join(dbPath, "GeoLite2-Country.mmdb"))
if err != nil {
return loc, errors.Wrap(err, "failed to open country db")
}
defer countryDB.Close()
ip := net.ParseIP(ipStr)
asn, err := asnDB.ASN(ip)
if err != nil {
return loc, err
}
country, err := countryDB.Country(ip)
if err != nil {
return loc, err
}
loc.ASN = asn.AutonomousSystemNumber
loc.NetworkName = asn.AutonomousSystemOrganization
loc.CountryCode = country.Country.IsoCode
return loc, nil
}
type avastResponse struct {
IP string `json:"ip"`
}
func avastLookup() (string, error) {
var parsed = new(avastResponse)
resp, err := http.Get("https://ip-info.ff.avast.com/v1/info")
if err != nil {
return "", errors.Wrap(err, "failed to perform request")
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", errors.Wrap(err, "failed to read response body")
}
err = json.Unmarshal([]byte(body), &parsed)
if err != nil {
return "", errors.Wrap(err, "failed to parse json")
}
return parsed.IP, nil
}
func akamaiLookup() (string, error) {
// This is a domain fronted request to akamai
client := &http.Client{}
req, err := http.NewRequest("GET", "https://a248.e.akamai.net/", nil)
if err != nil {
return "", errors.Wrap(err, "failed to create NewRequest")
}
req.Host = "whatismyip.akamai.com"
resp, err := client.Do(req)
if err != nil {
return "", errors.Wrap(err, "failed to perform request")
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", errors.Wrap(err, "failed to read response body")
}
return string(body), nil
}
type lookupFunc func() (string, error)
var lookupServices = []lookupFunc{
avastLookup,
akamaiLookup,
}
// IPLookup gets the users IP address from a IP lookup service
func IPLookup() (string, error) {
rand.Seed(time.Now().UnixNano())
var (
err error
ipStr string
)
retries := 3
for retries > 0 {
lookup := lookupServices[rand.Intn(len(lookupServices))]
ipStr, err = lookup()
if err == nil {
return ipStr, nil
}
retries--
}
return "", errors.Wrap(err, "exceeded maximum retries")
}
// GeoIPLookup does a geoip lookup and returns location information
func GeoIPLookup(dbPath string) (*LocationInfo, error) {
ipStr, err := IPLookup()
if err != nil {
return nil, err
}
location, err := LookupLocation(dbPath, ipStr)
if err != nil {
return nil, err
}
return &location, nil
}

View File

@ -13,7 +13,7 @@ import (
// RequiredDirs returns the required ooni home directories
func RequiredDirs(home string) []string {
requiredDirs := []string{}
requiredSubdirs := []string{"db", "msmts", "geoip"}
requiredSubdirs := []string{"assets", "db", "msmts"}
for _, d := range requiredSubdirs {
requiredDirs = append(requiredDirs, filepath.Join(home, d))
}
@ -25,9 +25,9 @@ func ConfigPath(home string) string {
return filepath.Join(home, "config.json")
}
// GeoIPDir returns the geoip data dir for the given OONI Home
func GeoIPDir(home string) string {
return filepath.Join(home, "geoip")
// AssetsDir returns the assets data dir for the given OONI Home
func AssetsDir(home string) string {
return filepath.Join(home, "assets")
}
// DBDir returns the database dir for the given name

10
version/version.go Normal file
View File

@ -0,0 +1,10 @@
// Package version contains version information
package version
const (
// Version is the software version
Version = "3.0.0-beta.3"
// UserAgent is the OONI user-agent header
UserAgent = "ooniprobe-desktop/" + Version
)