transferstats

package
v0.0.12-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2016 License: GPL-3.0 Imports: 8 Imported by: 0

README

transferstats Package

This provides a net.Conn interface implementation that can be put in a chain of connections and used to collect transfer statistics for the network traffic passing through it.

Total bytes transferred is recorded, as well as per-hostname bytes transferred stats for HTTP and HTTPS traffic (as long as the HTTPS traffic contains SNI information). Which hostnames are recorded is specified by a set of regular expressions.

(TODO: More info.)

Documentation

Overview

Package stats counts and keeps track of session stats. These are per-domain bytes transferred and total bytes transferred.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PutBackStatsForServer

func PutBackStatsForServer(serverID string, accumulatedStats *AccumulatedStats)

PutBackStatsForServer re-adds a set of server stats to the collection.

func ReportRecentBytesTransferredForServer

func ReportRecentBytesTransferredForServer(serverID string) (sent, received int64)

ReportRecentBytesTransferredForServer returns bytes sent and received since the last call to ReportRecentBytesTransferredForServer. The accumulated sent and received are reset to 0 by this call.

Types

type AccumulatedStats

type AccumulatedStats struct {
	// contains filtered or unexported fields
}

AccumulatedStats holds the Psiphon Server API status request data for a given server. To accommodate status requests that may fail, and be retried, the TakeOutStatsForServer/PutBackStatsForServer procedure allows the requester to check out stats for reporting and merge back stats for a later retry.

func TakeOutStatsForServer

func TakeOutStatsForServer(serverID string) (accumulatedStats *AccumulatedStats)

TakeOutStatsForServer borrows the AccumulatedStats for the specified server. When we fail to report these stats, resubmit them with PutBackStatsForServer. Stats will continue to be accumulated between TakeOut and PutBack calls. The recentBytes values are unaffected by TakeOut/PutBack. Returns empty stats if the serverID is not found.

func (AccumulatedStats) GetStatsForStatusRequest

func (stats AccumulatedStats) GetStatsForStatusRequest() (map[string]int64, int64)

GetStatsForStatusRequest summarizes AccumulatedStats data as required for the Psiphon Server API status request.

type Conn

type Conn struct {
	net.Conn
	// contains filtered or unexported fields
}

Conn is to be used as an intermediate link in a chain of net.Conn objects. It inspects requests and responses and derives stats from them.

func NewConn

func NewConn(nextConn net.Conn, serverID string, regexps *Regexps) *Conn

NewConn creates a Conn. serverID can be anything that uniquely identifies the server; it will be passed to TakeOutStatsForServer() when retrieving the accumulated stats.

func (*Conn) Read

func (conn *Conn) Read(buffer []byte) (n int, err error)

Read is called when responses to requests are being read from the remote server.

func (*Conn) Write

func (conn *Conn) Write(buffer []byte) (n int, err error)

Write is called when requests are being written out through the tunnel to the remote server.

type Regexps

type Regexps []regexpReplace

Regexps holds the regular expressions and replacement strings used for transforming URLs and hostnames into a stats-appropriate forms.

func MakeRegexps

func MakeRegexps(pageViewRegexes, httpsRequestRegexes []map[string]string) (regexps *Regexps, notices []string)

MakeRegexps takes the raw string-map form of the regex-replace pairs returned by the server handshake and turns them into a usable object.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL