Commit graph

194 commits

Author SHA1 Message Date
Arlo Breault
015958fbe6 Intermediary refactor teasing apart http / ipc
Introduces an IPC struct and moves the logic out of the http handlers
and into methods on that.
2021-07-08 12:32:35 -04:00
meskio
7a1857c42f
Make the proxy to report the number of clients to the broker
So the assignment of proxies is based on the load. The number of clients
is ronded down to 8. Existing proxies that doesn't report the number
of clients will be distributed equaly to new proxies until they get 8
clients, that is okish as the existing proxies do have a maximum
capacity of 10.

Fixes #40048
2021-07-07 19:36:20 +02:00
Cecylia Bocovich
270eb21803 Encode client-broker messages as json in HTTP body
Send the client poll request and response in a json-encoded format in
the HTTP request body rather than sending the data in HTTP headers. This
will pave the way for using domain-fronting alternatives for the
Snowflake rendezvous.
2021-06-02 09:52:42 -04:00
Arlo Breault
7ef49272fa Remove sync.Once from around logMetrics
Follow up to 160ae2d

Analysis by @dcf,

> I don't think the sync.Once around logMetrics is necessary anymore.
Its original purpose was to inhibit logging on later file handles of
metrics.log, if there were more than one opened. See 171c55a9 and #29734
(comment 2593039) "Making a singleton *Metrics variable causes problems
with how Convey does tests. It shouldn't be called more than once, but
for now I'm using sync.Once on the logging at least so it's explicit."
Commit ba4fe1a7 changed it so that metrics.log is opened in main, used
to create a *log.Logger, and that same instance of *log.Logger is passed
to both NewMetrics and NewBrokerContext. It's safe to share the same
*log.Logger across multiple BrokerContext.
2021-05-20 15:39:30 -04:00
Arlo Breault
160ae2dd71 Make promMetrics not a global
Doesn't seem like it needs to exist outside of the metrics struct.

Also, the call to logMetrics is moved to the constructor.  A metrics
instance is only created when a BrokerContext is created, which only
happens at startup.  The sync of only doing that once is left for
documentation purposes, since it doesn't hurt, but also seems redundant.
2021-05-18 20:07:43 -04:00
Cecylia Bocovich
af6e2c30e1 Replace default with custom prometheus registry
The default prometheus registry exports data that may be useful for
side-channel attacks. This removes all of the default metrics and makes
sure we are only reporting snowflake metrics from the broker.
2021-04-26 14:18:50 -04:00
Cecylia Bocovich
2a310682b5 Add new gauge to show currently available proxies 2021-04-26 14:18:50 -04:00
Cecylia Bocovich
92bd900bc5 Implement binned counts for polling metrics 2021-04-26 14:07:55 -04:00
Cecylia Bocovich
83ef0b6f6d Export snowflake broker metrics for prometheus
This change adds a prometheus exporter for our existing snowflake broker
metrics. Current values for the metrics can be fetched by sending a GET
request to /prometheus.
2021-04-22 10:39:35 -04:00
Cecylia Bocovich
bae0bacbfd Classify proxies with unknown NATs as restricted 2021-01-25 14:05:24 -05:00
Philipp Winter
5efcde5187
Sort snowflake-ips stats by country count.
We currently don't sort the snowflake-ips metrics:

    snowflake-ips CA=1,DE=1,AR=1,NL=1,FR=1,GB=2,US=4,CH=1

To facilitate eyeballing our metrics, this patch sorts snowflake-ips by
value.  If the value is identical, we sort by string, i.e.:

    snowflake-ips US=4,GB=2,AR=1,CA=1,CH=1,DE=1,FR=1,NL=1

This patch fixes tpo/anti-censorship/pluggable-transports/snowflake#40011
2020-11-27 11:20:40 -08:00
Cecylia Bocovich
3c3317503e Update broker stats to include info on NAT types
As we now partition proxies by NAT type, our stats are more useful if they
capture how many proxies of each type we have, and information on
whether we have enough proxies of the right NAT type for our clients.
This change adds proxy counts by NAT type and binned counts of denied clients by NAT type.
2020-08-24 09:39:17 -04:00
Cecylia Bocovich
046dab865f Have broker pass client NAT type to proxy
This will allow browser-based proxies that are unable to determine their
NAT type to conservatively label themselves as restricted NATs if they
fail to work with clients that have restricted NATs.
2020-07-06 13:16:03 -04:00
Cecylia Bocovich
0052c0e10c Add a new heap at the broker for restricted flakes
Now when proxies poll, they provide their NAT type to the broker. This
introduces a new snowflake heap of just restricted snowflakes that the
broker can pull from if the client has a known, unrestricted NAT. All
other clients will pull from a heap of snowflakes with unrestricted or
unknown NAT topologies.
2020-07-06 13:16:03 -04:00
Cecylia Bocovich
f6cf9a453b Implement NAT discover for go standalone proxies 2020-07-06 13:16:03 -04:00
Arlo Breault
f58c865d82 Add unsafe logging 2020-03-25 11:53:24 -04:00
Cecylia Bocovich
06298eec73 Added another lock to protect broker stats
Added another lock to the metrics struct to synchronize accesses to the
broker stats. There's a possible race condition if stats are updated at
the same time they are being logged.
2019-12-05 10:17:20 -05:00
Cecylia Bocovich
42e16021c4 Add tests to check for data race in broker
We had some data races in the broker that occur when proxies and clients
modify the heap/snowflake map at the same time. This test has a client
and proxy access the broker simultaneously to check for data races.
2019-12-05 10:16:34 -05:00
Cecylia Bocovich
dccc15a6e9 Add synchronization to prevent race in broker
There's a race condition in the broker where both the proxy and the
client processes try to pop/remove the same snowflake from the heap.
This patch adds synchronization to prevent simultaneous accesses to
snowflakes.
2019-12-05 09:47:26 -05:00
Cecylia Bocovich
94de69aa36 Updated broker specification and comments 2019-11-28 13:52:58 -05:00
Cecylia Bocovich
97554e03e4 Updated proxyType variable name for readability 2019-11-28 13:52:58 -05:00
Cecylia Bocovich
981abffbd9 Add proxy type to stats exported by broker 2019-11-28 13:52:58 -05:00
Cecylia Bocovich
7277bb37cd Update broker--proxy protocol with proxy type
Proxies now include information about what type they are when they poll
for client offers. The broker saves this information along with
snowflake ids and outputs it on the /debug page.
2019-11-28 13:52:58 -05:00
Cecylia Bocovich
7557e96a8d Remove unnecessary logging at broker 2019-11-13 15:01:03 -05:00
Cecylia Bocovich
c4ae64905b Redo protocol for proxy--broker messages
Switch to containing all communication between the proxy and the broker
in the HTTP response body. This will make things easier if we ever use
something other than HTTP communicate between different actors in the
snowflake system.

Other changes to the protocol are as follows:
- requests are accompanied by a version number so the broker can be
backwards compatable if desired in the future
- all responses are 200 OK unless the request was badly formatted
2019-11-13 10:54:48 -05:00
Shane Howearth
3cfceb3755 Handle generated errors in broker 2019-10-08 10:13:29 -04:00
Cecylia Bocovich
f3be34a459 Removed extraneous log messages
Many of our log messages were being used to generate metrics, but are
now being aggregated and logged to a separate metrics log file and so we
don't need them in the regular logs anymore.

This addresses the goal of ticket #30830, to remove unecessary messages
and keep broker logs for debugging purposes.
2019-09-19 16:48:14 -04:00
Cecylia Bocovich
00eb4aadf5 Modified broker /debug page to display counts only
The broker /debug page was displaying proxy IDs and roundtrip times. As
serna pointed out in bug #31460, the proxy IDs can be used to launch a
denial of service attack. As the metrics team pointed out on #21315, the
round trip time average can be potentially sensitive.

This change displays only proxy counts and uses ID lengths to
distinguish between standalone proxy-go instances and browser-based
snowflake proxies.
2019-08-27 10:01:00 -04:00
Cecylia Bocovich
0aef40100a Implemented handler to fetch broker stats
This implements a handler at https://[snowflake-broker]/metrics for the
snowflake collecTor module to fetch stats from the broker. Logged
metrics are copied out to the response with a text/plain; charset=utf-8
content type. This implements bug #31376.
2019-08-16 09:12:49 -04:00
Cecylia Bocovich
19244c7146 Merge branch 'ticket21315' 2019-06-28 17:31:02 -04:00
Cecylia Bocovich
908cf3fc64 Updated tests to check new stats
Updated the tests to pass with our new snowflake-ips-total stat
2019-06-25 10:06:00 -04:00
Cecylia Bocovich
8f2dc3563b Added a metric that sums available snowflakes
Added another metrics item that counts the total availabel snowflakes
(unique by IP address)
2019-06-25 09:33:45 -04:00
Cecylia Bocovich
f779013b2d Fixed small formatting errors of log output
- removed trailing ","s
- removed unecessary space before seconds
2019-06-14 17:09:06 -04:00
Cecylia Bocovich
0767a637c1 Changed variable names/types to be more reasonable
Also moved the geoip check to occur after we've make sure the proxy IP
hasn't yet been recorded. This is will cut down on unecessary
computation.
2019-06-14 17:00:31 -04:00
Cecylia Bocovich
92d61f2555 Added a comment for the metrics specification 2019-06-12 10:17:55 -04:00
Cecylia Bocovich
fe3356a54d Unit tests for metrics code
Added unit tests for metrics logging. Refactored the logMetrics()
function to allow for easier testing
2019-06-12 10:14:21 -04:00
Cecylia Bocovich
25f059f4c4 Log geoip stats of proxies by unique IP
Change it so that we log the geoip country code of proxies if they poll
within the current metrics epoch. We make sure we log by unique IP
address
2019-06-11 15:43:59 -04:00
Cecylia Bocovich
c782ebdcea Format output to meet specification
Output is now printed out in Tor Directory Protocol Format, as specified
in https://trac.torproject.org/projects/tor/ticket/21315#comment:19.
2019-06-11 15:01:05 -04:00
Cecylia Bocovich
175b8efb04 Bin metrics to nearest mult of 8 2019-06-11 14:27:42 -04:00
Cecylia Bocovich
0293674e38 Zero out counts for next time step 2019-06-11 14:19:14 -04:00
Cecylia Bocovich
d57cd07599 Implemented count metrics for broker events
Added three new metrics:
- proxyIdleCount counts the number of times a proxy polls and receives
no snowflakes
- clientDeniedCount counts the number of times a client requested a
snowflake but none were available
- clientProxyMatchCount counts the number of times a client successfully
received a snowflake
2019-06-11 14:16:01 -04:00
Cecylia Bocovich
64ce7dff1b Changed time resolution for metrics collection
Set the resolution of metrics data collection to be every 24 hours
2019-06-11 13:44:59 -04:00
Philipp Winter
11efa42e4c
Cache certificates across program restarts.
So far, we request a certificate each time we start the broker.  Let's
Encrypt maintains several rate limiters and if we exceed one of them, we
won't get a certificate.  Worse, since we don't store certificates, we
won't even be able to use an old one.

This patch uses autocert's DirCache structure to cache certificates on
disk.

This patch fixes <https://bugs.torproject.org/30512>.
2019-06-03 15:50:35 -07:00
Cecylia Bocovich
0842dad38e Added tests to check large read guards 2019-05-28 13:29:59 -04:00
Cecylia Bocovich
1d76d3ca2e Implement limitedRead function for client side
MaxBytesReader is only documented for server side reads, so we're using
a local limitedRead function instead that uses an io.LimitedReader.

Declared limits in a commented constant
2019-05-28 13:29:59 -04:00
Cecylia Bocovich
ce3101d016 Guard against large reads
This is a fix for #26348
2019-05-28 13:29:59 -04:00
Arlo Breault
dd927050d9 Appease go vets complaints about passing locks by value 2019-05-16 12:58:25 -04:00
Arlo Breault
b77a99b565 Fix broker tests
NewBrokerContext now requires a logger so give it one to discard the
logs.
2019-05-16 12:34:21 -04:00
Cecylia Bocovich
6b002c5f22 Merge branch 'geoip_squashed' 2019-05-15 11:07:33 -04:00
Cecylia Bocovich
1133e01363 Added an option to use a conventional certificate 2019-05-14 17:14:39 -04:00