示例#1
0
func TestLoggly(t *testing.T) {
	var buf bytes.Buffer
	var result map[string]interface{}
	loggly := loggly.New("token not required")
	loggly.Writer = &buf
	lw := logglyErrorWriter{client: loggly}
	golog.SetOutputs(lw, nil)
	log := golog.LoggerFor("test")

	log.Error("")
	if assert.NoError(t, json.Unmarshal(buf.Bytes(), &result), "Unmarshal error") {
		assert.Equal(t, "ERROR test", result["locationInfo"])
		assert.Regexp(t, regexp.MustCompile("logging_test.go:([0-9]+)"), result["message"])
	}

	buf.Reset()
	log.Error("short message")
	if assert.NoError(t, json.Unmarshal(buf.Bytes(), &result), "Unmarshal error") {
		assert.Equal(t, "ERROR test", result["locationInfo"])
		assert.Regexp(t, regexp.MustCompile("logging_test.go:([0-9]+) short message"), result["message"])
	}

	buf.Reset()
	log.Error("message with: reason")
	if assert.NoError(t, json.Unmarshal(buf.Bytes(), &result), "Unmarshal error") {
		assert.Equal(t, "ERROR test", result["locationInfo"])
		assert.Regexp(t, "logging_test.go:([0-9]+) message with: reason", result["message"])
	}

	buf.Reset()
	log.Error("deep reason: message with: reason")
	if assert.NoError(t, json.Unmarshal(buf.Bytes(), &result), "Unmarshal error") {
		assert.Equal(t, "ERROR test", result["locationInfo"])
		assert.Equal(t, "message with: reason", result["message"], "message should be last 2 chunks")
	}

	buf.Reset()
	log.Error("deep reason: an url https://a.com in message: reason")
	if assert.NoError(t, json.Unmarshal(buf.Bytes(), &result), "Unmarshal error") {
		assert.Equal(t, "an url https://a.com in message: reason", result["message"], "should not truncate url")
	}

	buf.Reset()
	log.Error("deep reason: an url 127.0.0.1:8787 in message: reason")
	if assert.NoError(t, json.Unmarshal(buf.Bytes(), &result), "Unmarshal error") {
		assert.Equal(t, "ERROR test", result["locationInfo"])
		assert.Equal(t, "an url 127.0.0.1:8787 in message: reason", result["message"], "should not truncate url")
	}

	buf.Reset()
	longPrefix := "message with: really l"
	longMsg := longPrefix + strings.Repeat("o", 100) + "ng reason"
	log.Error(longMsg)
	if assert.NoError(t, json.Unmarshal(buf.Bytes(), &result), "Unmarshal error") {
		assert.Equal(t, "ERROR test", result["locationInfo"])

		assert.Regexp(t, regexp.MustCompile("logging_test.go:([0-9]+) "+longPrefix+"(o+)"), result["message"])
		assert.Equal(t, 100, len(result["message"].(string)))
	}
}
示例#2
0
func sendTestRequest(client *http.Client, addr string) error {
	log := golog.LoggerFor("protected")

	req, err := http.NewRequest("GET", "http://"+addr+"/", nil)
	if err != nil {
		return fmt.Errorf("Error constructing new HTTP request: %s", err)
	}
	req.Header.Add("Connection", "keep-alive")
	resp, err := client.Do(req)
	if err != nil {
		return fmt.Errorf("Could not make request to %s: %s", addr, err)
	}
	_, err = ioutil.ReadAll(resp.Body)
	if err != nil {
		return fmt.Errorf("Error reading response body: %s", err)
	}
	resp.Body.Close()
	log.Debugf("Successfully processed request to %s", addr)
	return nil
}
示例#3
0
	"github.com/getlantern/golog"

	"github.com/getlantern/flashlight/pubsub"
	"github.com/getlantern/flashlight/ui"
)

const (
	messageType = `GeoLookup`

	basePublishSeconds     = 30
	publishSecondsVariance = basePublishSeconds - 10
	retryWaitMillis        = 100
)

var (
	log = golog.LoggerFor("flashlight.geolookup")

	service  *ui.Service
	client   atomic.Value
	cfgMutex sync.Mutex
	location atomic.Value
)

func GetLocation() *geolookup.City {
	l := location.Load()
	if l == nil {
		return nil
	}
	return l.(*geolookup.City)
}
示例#4
0
文件: config.go 项目: shizhh/lantern
	"github.com/getlantern/flashlight/client"
	"github.com/getlantern/flashlight/globals"
	"github.com/getlantern/flashlight/server"
	"github.com/getlantern/flashlight/statreporter"
)

const (
	CloudConfigPollInterval = 1 * time.Minute
	cloudflare              = "cloudflare"
	etag                    = "X-Lantern-Etag"
	ifNoneMatch             = "X-Lantern-If-None-Match"
)

var (
	log                 = golog.LoggerFor("flashlight.config")
	m                   *yamlconf.Manager
	lastCloudConfigETag = map[string]string{}
	httpClient          atomic.Value
)

type Config struct {
	Version       int
	CloudConfig   string
	CloudConfigCA string
	Addr          string
	Role          string
	InstanceId    string
	CpuProfile    string
	MemProfile    string
	UIAddr        string // UI HTTP server address
示例#5
0
import (
	"os"
	"runtime"
	"sync"

	"github.com/getlantern/aws-sdk-go/gen/cloudfront"
	"github.com/getlantern/golog"
	"github.com/getlantern/peerscanner/cfr"
)

const (
	COMMENT = "TEST -- DELETE"
)

var (
	log = golog.LoggerFor("cfrjanitor")
)

func main() {
	numProcs := runtime.NumCPU() * 2
	runtime.GOMAXPROCS(numProcs)
	numWorkers := numProcs * 4
	c := getCfr()
	workCh := make(chan *cfr.Distribution)
	wg := sync.WaitGroup{}
	wg.Add(numWorkers)
	log.Debugf("Spawning %v workers", numWorkers)
	for i := 0; i < numWorkers; i++ {
		go work(c, workCh, &wg)
	}
	dists, err := cfr.ListDistributions(c)
示例#6
0
文件: dialer.go 项目: shizhh/lantern
	"sync"
	"time"

	"github.com/getlantern/connpool"
	"github.com/getlantern/enproxy"
	"github.com/getlantern/golog"
	"github.com/getlantern/proxy"
	"github.com/getlantern/tlsdialer"
)

const (
	CONNECT = "CONNECT" // HTTP CONNECT method
)

var (
	log = golog.LoggerFor("fronted")

	// Cutoff for logging warnings about a dial having taken a long time.
	longDialLimit = 10 * time.Second

	// idleTimeout needs to be small enough that we stop using connections
	// before the upstream server/CDN closes them itself.
	// TODO: make this configurable.
	idleTimeout = 10 * time.Second
)

// Dialer is a domain-fronted proxy.Dialer.
type Dialer interface {
	proxy.Dialer

	// HttpClientUsing creates a simple domain-fronted HTTP client using the
示例#7
0
var (
	help                = flag.Bool("help", false, "Get usage help")
	masqueradesInFile   = flag.String("masquerades", "", "Path to file containing list of pasquerades to use, with one space-separated 'ip domain' pair per line (e.g. masquerades.txt)")
	masqueradesOutFile  = flag.String("masquerades-out", "", "Path, if any, to write the go-formatted masquerades configuration.")
	blacklistFile       = flag.String("blacklist", "", "Path to file containing list of blacklisted domains, which will be excluded from the configuration even if present in the masquerades file (e.g. blacklist.txt)")
	proxiedSitesDir     = flag.String("proxiedsites", "proxiedsites", "Path to directory containing proxied site lists, which will be combined and proxied by Lantern")
	proxiedSitesOutFile = flag.String("proxiedsites-out", "", "Path, if any, to write the go-formatted proxied sites configuration.")
	minFreq             = flag.Float64("minfreq", 3.0, "Minimum frequency (percentage) for including CA cert in list of trusted certs, defaults to 3.0%")

	fallbacksFile    = flag.String("fallbacks", "fallbacks.yaml", "File containing yaml dict of fallback information")
	fallbacksOutFile = flag.String("fallbacks-out", "", "Path, if any, to write the go-formatted fallback configuration.")
)

var (
	log = golog.LoggerFor("genconfig")

	masquerades []string

	blacklist    = make(filter)
	proxiedSites = make(filter)
	fallbacks    map[string]*client.ChainedServerInfo
	ftVersion    string

	inputCh       = make(chan string)
	masqueradesCh = make(chan *masquerade)
	wg            sync.WaitGroup
)

type filter map[string]bool
示例#8
0
	"net/http"
	"net/http/httputil"
	"strconv"
	"time"

	"github.com/getlantern/errors"
	"github.com/getlantern/golog"
	"github.com/getlantern/idletiming"
	"github.com/getlantern/ops"
	"github.com/getlantern/proxy"

	"github.com/getlantern/http-proxy/buffers"
	"github.com/getlantern/http-proxy/filters"
)

var log = golog.LoggerFor("httpconnect")

type Options struct {
	IdleTimeout  time.Duration
	AllowedPorts []int
	Dialer       func(network, address string) (net.Conn, error)
}

type httpConnectHandler struct {
	*Options
	intercept proxy.Interceptor
}

func New(opts *Options) filters.Filter {
	if opts.Dialer == nil {
		opts.Dialer = func(network, address string) (net.Conn, error) {
示例#9
0
	r Reporter
}

// Measured is the controller to report statistics
type Measured struct {
	reporters     []Reporter
	maxBufferSize int
	chTraffic     chan *Traffic
	traffic       map[string]*TrafficTracker
	chStop        chan struct{}
	stopped       int32
	mutex         sync.Mutex
}

var (
	log = golog.LoggerFor("measured")
)

// DialFunc is the type of function measured can wrap
type DialFunc func(net, addr string) (net.Conn, error)

// New creates a new Measured instance
func New(maxBufferSize int) *Measured {
	return &Measured{
		maxBufferSize: maxBufferSize,
		chTraffic:     make(chan *Traffic, maxBufferSize),
		traffic:       make(map[string]*TrafficTracker, maxBufferSize),
		chStop:        make(chan struct{}),
		stopped:       1,
	}
}
示例#10
0
	"sync"

	"github.com/getlantern/detour"
	"github.com/getlantern/golog"
	"github.com/getlantern/proxiedsites"

	"github.com/getlantern/flashlight/config"
	"github.com/getlantern/flashlight/ui"
)

const (
	messageType = `ProxiedSites`
)

var (
	log = golog.LoggerFor("flashlight.proxiedsites")

	service    *ui.Service
	PACURL     string
	startMutex sync.Mutex
)

func Configure(cfg *proxiedsites.Config) {
	delta := proxiedsites.Configure(cfg)
	startMutex.Lock()

	if delta != nil {
		updateDetour(delta)
	}
	if service == nil {
		// Initializing service.
示例#11
0
文件: server.go 项目: shizhh/lantern
	"github.com/getlantern/go-igdman/igdman"
	"github.com/getlantern/golog"
	"github.com/getlantern/yaml"
	"github.com/hashicorp/golang-lru"

	"github.com/getlantern/flashlight/globals"
	"github.com/getlantern/flashlight/statreporter"
	"github.com/getlantern/flashlight/statserver"
)

const (
	PortmapFailure = 50
)

var (
	log               = golog.LoggerFor("flashlight.server")
	registerPeriod    = 5 * time.Minute
	frontingProviders = map[string]func(*http.Request) bool{
		// WARNING: If you add a provider here, keep in mind that Go's http
		// library normalizes all header names so the first letter of every
		// dash-separated "word" is uppercase while all others are lowercase.
		// Also, try and check more than one header to lean on the safe side.
		"cloudflare": func(req *http.Request) bool {
			return hasHeader(req, "Cf-Connecting-Ip") || hasHeader(req, "Cf-Ipcountry") || hasHeader(req, "Cf-Ray") || hasHeader(req, "Cf-Visitor")
		},
		"cloudfront": func(req *http.Request) bool {
			return hasHeader(req, "X-Amz-Cf-Id") || headerMatches(req, "User-Agent", "Amazon Cloudfront")
		},
	}
)
示例#12
0
	"github.com/getlantern/flashlight/client"
	"github.com/getlantern/golog"

	socks "github.com/getlantern/lantern-mobile/lantern/socks"
)

// Errors introduced by the interceptor service
var (
	defaultClient Interceptor
	dialTimeout   = 20 * time.Second
	// threshold of errors that we are withstanding
	maxErrCount = 15

	statsInterval = 15 * time.Second
	log           = golog.LoggerFor("lantern-android.interceptor")

	ErrTooManyFailures = errors.New("Too many connection failures")
	ErrNoSocksProxy    = errors.New("Unable to start local SOCKS proxy")
	ErrDialTimeout     = errors.New("Error dialing tunnel: timeout")
)

type DialFunc func(network, addr string) (net.Conn, error)

// Interceptor is responsible for intercepting
// traffic on the VPN interface.
type Interceptor struct {
	client *client.Client

	clientGone bool
示例#13
0
package listeners

import (
	"errors"
	"math"
	"net"
	"net/http"
	"sync/atomic"
	"time"

	"github.com/getlantern/golog"
)

var (
	log = golog.LoggerFor("listeners")
)

type limitedListener struct {
	net.Listener

	maxConns    uint64
	numConns    uint64
	idleTimeout time.Duration

	stopped int32
	stop    chan bool
	restart chan bool
}

func NewLimitedListener(l net.Listener, maxConns uint64) net.Listener {
	if maxConns <= 0 {
示例#14
0
	"net/url"
	"runtime"
	"strconv"

	"github.com/getlantern/flashlight/util"
	"github.com/getlantern/golog"
)

const (
	ApiEndpoint       = `https://ssl.google-analytics.com/collect`
	ProtocolVersion   = "1"
	DefaultInstanceId = "555"
)

var (
	log        = golog.LoggerFor("analytics")
	httpClient *http.Client
	ip         string
)

type HitType string

const (
	PageViewType HitType = "pageview"
	EventType    HitType = "event"
)

type PageView struct {
	Hostname string `param:"dh"`
	Pagename string `param:"dp"`
	Title    string `param:"dt"`
示例#15
0
// clients can make requests to specific domains.
package ratelimiter

import (
	"fmt"
	"net"
	"net/http"
	"sync"
	"time"

	"github.com/getlantern/golog"
	"github.com/getlantern/http-proxy/filters"
	"github.com/hashicorp/golang-lru"
)

var log = golog.LoggerFor("ratelimiter")

type ratelimiter struct {
	hostPeriods          map[string]time.Duration
	hostAccessesByClient *lru.Cache
	mx                   sync.Mutex
}

// New creates a new rate limiting filter that only allows access to the hosts
// listed in the given hostPeriods, and limits the periodicity of requests to
// each host to the given duration. It limits the number of clients tracked to
// the the numClients with the most recent activity.
func New(numClients int, hostPeriods map[string]time.Duration) filters.Filter {
	if numClients <= 0 {
		numClients = 5000
	}
示例#16
0
package yamlconf

import (
	"fmt"
	"os"
	"sync"
	"time"

	"github.com/getlantern/deepcopy"
	"github.com/getlantern/golog"
)

var (
	log = golog.LoggerFor("yamlconf")
)

// Config is the interface for configuration objects that provide the in-memory
// representation of yaml configuration managed by yamlconf.
type Config interface {
	GetVersion() int

	SetVersion(version int)

	ApplyDefaults()
}

// Manager exposes a facility for managing configuration a YAML configuration
// file. After creating a Manager, one must call the Init() method to start the
// necessary background processing.  If you set a CustomPoll function, you need
// to call StartPolling() also.
//
示例#17
0
	"time"

	"github.com/getlantern/golog"
)

const (
	// Addresses for Administratively Scoped IP Multicast are in the space 239/8
	multicastIP       = "232.77.77.77"
	multicastPort     = "9864"
	multicastAddress  = multicastIP + ":" + multicastPort
	defaultPeriod     = 9
	defaultFailedTime = 30 // Seconds until a peer is considered failed
)

var (
	log = golog.LoggerFor("multicast")
)

type eventCallback func(string, []PeerInfo)

// Multicast servent main structure
type Multicast struct {
	period             int    // multicast period (in secs, 10 by default)
	payload            string // Will be appended to the messages
	conn               *net.UDPConn
	addr               *net.UDPAddr
	failedTime         int           // timeout for peers' hello messages, 0 means no timeout
	addPeerCallback    eventCallback // Callback called when a peer is added (added, all)
	removePeerCallback eventCallback // Callback called when a peer is removed (removed, all)
	quit               chan bool
	helloTicker        *time.Ticker
示例#18
0
	"os"
	"time"

	"github.com/getlantern/golog"

	"github.com/getlantern/http-proxy/commonfilter"
	"github.com/getlantern/http-proxy/forward"
	"github.com/getlantern/http-proxy/httpconnect"
	"github.com/getlantern/http-proxy/listeners"
	"github.com/getlantern/http-proxy/logging"
	"github.com/getlantern/http-proxy/server"
)

var (
	testingLocal = false
	log          = golog.LoggerFor("http-proxy")

	help      = flag.Bool("help", false, "Get usage help")
	keyfile   = flag.String("key", "", "Private key file name")
	certfile  = flag.String("cert", "", "Certificate file name")
	https     = flag.Bool("https", false, "Use TLS for client to proxy communication")
	addr      = flag.String("addr", ":8080", "Address to listen")
	maxConns  = flag.Uint64("maxconns", 0, "Max number of simultaneous connections allowed connections")
	idleClose = flag.Uint64("idleclose", 30, "Time in seconds that an idle connection will be allowed before closing it")
)

func main() {
	var err error

	_ = flag.CommandLine.Parse(os.Args[1:])
	if *help {
示例#19
0
	"github.com/getlantern/flashlight/client"
	"github.com/getlantern/flashlight/config"
	"github.com/getlantern/flashlight/geolookup"
	"github.com/getlantern/flashlight/logging"
)

const (
	// While in development mode we probably would not want auto-updates to be
	// applied. Using a big number here prevents such auto-updates without
	// disabling the feature completely. The "make package-*" tool will take care
	// of bumping this version number so you don't have to do it by hand.
	DefaultPackageVersion = "9999.99.99"
)

var (
	log = golog.LoggerFor("flashlight")

	// compileTimePackageVersion is set at compile-time for production builds
	compileTimePackageVersion string

	PackageVersion = bestPackageVersion()

	Version      string
	RevisionDate string // The revision date and time that is associated with the version string.
	BuildDate    string // The actual date and time the binary was built.

	cfgMutex sync.Mutex
)

func bestPackageVersion() string {
	if compileTimePackageVersion != "" {
示例#20
0
文件: tarfs.go 项目: shizhh/lantern
	"net/http"
	"os"
	"path"
	"path/filepath"
	"strings"
	"time"

	"github.com/getlantern/golog"
)

const (
	ExitLocalDirUnavailable = 1
)

var (
	log            = golog.LoggerFor("tarfs")
	fileTimestamp  = time.Now()
	emptyFileInfos = []os.FileInfo{}
)

// FileSystem is a tarfs filesystem. It exposes a Get method for accessing
// resources by path. It also implements http.FileSystem for use with
// http.FileServer.
type FileSystem struct {
	files map[string][]byte
	local string
}

// New creates a new FileSystem using the given in-memory tar data. If local is
// a non-empty string, the resulting FileSystem will first look for resources in
// the local file system before returning an embedded resource.
示例#21
0
	"io"
	"net"
	"net/http"
	"net/http/httputil"
	"net/url"
	"time"

	"github.com/getlantern/golog"
	"github.com/getlantern/idletiming"
	"github.com/getlantern/ops"

	"github.com/getlantern/http-proxy/buffers"
	"github.com/getlantern/http-proxy/filters"
)

var log = golog.LoggerFor("forward")

type Options struct {
	IdleTimeout  time.Duration
	Rewriter     RequestRewriter
	Dialer       func(network, address string) (net.Conn, error)
	RoundTripper http.RoundTripper
}

type forwarder struct {
	*Options
}

type RequestRewriter interface {
	Rewrite(r *http.Request)
}
示例#22
0
文件: interface.go 项目: 2722/lantern
package client

import (
	"github.com/getlantern/appdir"
	"github.com/getlantern/flashlight/config"
	"github.com/getlantern/flashlight/lantern"
	"github.com/getlantern/flashlight/logging"
	"github.com/getlantern/flashlight/settings"
	"github.com/getlantern/golog"
	"github.com/getlantern/lantern-mobile/lantern/interceptor"
	"github.com/getlantern/lantern-mobile/lantern/protected"
)

var (
	log         = golog.LoggerFor("lantern-android.client")
	i           *interceptor.Interceptor
	appSettings *settings.Settings

	trackingCodes = map[string]string{
		"FireTweet": "UA-21408036-4",
		"Lantern":   "UA-21815217-14",
	}
)

type Provider interface {
	Model() string
	Device() string
	Version() string
	AppName() string
	VpnMode() bool
	GetDnsServer() string
示例#23
0
// sites (cloud) and user-applied customizations to that list. It provides an
// implementation of the http.Handler interface that serves up a PAC file based
// on the currently active proxied sites (cloud + additions - deletions).
package proxiedsites

import (
	"sort"
	"sync"

	"github.com/getlantern/golog"

	"gopkg.in/fatih/set.v0"
)

var (
	log = golog.LoggerFor("proxiedsites")

	cs       *configsets
	cfgMutex sync.RWMutex
)

// Delta represents modifications to the proxied sites list.
type Delta struct {
	Additions []string `json:"Additions, omitempty"`
	Deletions []string `json:"Deletions, omitempty"`
}

// Merge merges the given delta into the existing one.
func (d *Delta) Merge(n *Delta) {
	oadd := toSet(d.Additions)
	odel := toSet(d.Deletions)
示例#24
0
	"os"
	"runtime"
	"strings"
	"sync"
)

var (
	help          = flag.Bool("help", false, "Get usage help")
	fallbacksFile = flag.String("fallbacks", "fallbacks.json", "File containing json array of fallback information")
	numConns      = flag.Int("connections", 1, "Number of simultaneous connections")

	expectedBody = "Google is built by a large team of engineers, designers, researchers, robots, and others in many different sites across the globe. It is updated continuously, and built with more tools and technologies than we can shake a stick at. If you'd like to help us out, see google.com/careers.\n"
)

var (
	log = golog.LoggerFor("checkfallbacks")
)

func main() {
	flag.Parse()

	if *help {
		flag.Usage()
		os.Exit(1)
	}

	numcores := runtime.NumCPU()
	runtime.GOMAXPROCS(numcores)
	log.Debugf("Using all %d cores on machine", numcores)

	fallbacks := loadFallbacks(*fallbacksFile)
示例#25
0
// package filepersist provdies a mechanism for persisting data to a file at a
// permanent location
package filepersist

import (
	"fmt"
	"io"
	"os"

	"github.com/getlantern/golog"
)

var (
	log = golog.LoggerFor("filepersist")
)

// Save saves the given data to the file at filename. If an existing file at
// that filename already exists, this simply chmods the existing file to match
// the given fileMode and otherwise leaves it alone.
func Save(filename string, data []byte, fileMode os.FileMode) error {
	log.Tracef("Attempting to open %v for creating, but only if it doesn't already exist", filename)
	file, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_EXCL, fileMode)
	if err != nil {
		if !os.IsExist(err) {
			return fmt.Errorf("Unexpected error opening %s: %s", filename, err)
		}

		log.Tracef("%s already exists, check to make sure contents is the same", filename)
		if dataMatches(filename, data) {
			log.Tracef("Data in %s matches expected, using existing", filename)
			chmod(filename, fileMode)
示例#26
0
文件: rotator.go 项目: 2722/lantern
package rotator

import (
	"io"

	"github.com/getlantern/golog"
)

var (
	log = golog.LoggerFor("sizerotator")
)

// Rotator interface
type Rotator interface {
	// a Write method, a Close method
	io.WriteCloser
	// WriteString writes strings to the file.
	WriteString(str string) (n int, err error)
}
示例#27
0
文件: client.go 项目: kidaa/lantern
	"net"
	"net/http"
	"net/http/httputil"
	"reflect"
	"sync"
	"time"

	"github.com/getlantern/balancer"
	"github.com/getlantern/fronted"
	"github.com/getlantern/golog"

	"github.com/getlantern/flashlight/globals"
)

var (
	log = golog.LoggerFor("flashlight.client")
)

// Client is an HTTP proxy that accepts connections from local programs and
// proxies these via remote flashlight servers.
type Client struct {
	// Addr: listen address in form of host:port
	Addr string

	// ReadTimeout: (optional) timeout for read ops
	ReadTimeout time.Duration

	// WriteTimeout: (optional) timeout for write ops
	WriteTimeout time.Duration

	// ProxyAll: (optional)  poxy all sites regardless of being blocked or not
示例#28
0
文件: server.go 项目: shizhh/lantern
package server

import (
	"fmt"

	"github.com/blang/semver"
	"github.com/getlantern/golog"
)

var log = golog.LoggerFor("autoupdate-server")

// Initiative type.
type Initiative string

const (
	INITIATIVE_NEVER  Initiative = "never"
	INITIATIVE_AUTO              = "auto"
	INITIATIVE_MANUAL            = "manual"
)

// PatchType represents the type of a binary patch, if any. Only bsdiff is supported
type PatchType string

const (
	PATCHTYPE_BSDIFF PatchType = "bsdiff"
	PATCHTYPE_NONE             = ""
)

// Params represent parameters sent by the go-update client.
type Params struct {
	// protocol version
示例#29
0
	"sync"
	"time"

	"github.com/getlantern/golog"

	"github.com/getlantern/flashlight/globals"
)

const (
	statshubUrlTemplate = "https://%s/stats/%s"

	countryDim = "country"
)

var (
	log = golog.LoggerFor("flashlight.statreporter")

	cfgMutex        sync.RWMutex
	currentReporter *reporter
)

type Config struct {
	// ReportingPeriod: how frequently to report
	ReportingPeriod time.Duration

	// StatshubAddr: the address of the statshub server to which to report
	StatshubAddr string
}

type reporter struct {
	cfg          *Config
示例#30
0
import (
	"net"
	"net/http"
	"reflect"

	"github.com/gorilla/context"

	"github.com/getlantern/golog"
	"github.com/getlantern/tlsdefaults"

	"github.com/getlantern/http-proxy/listeners"
)

var (
	testingLocal = false
	log          = golog.LoggerFor("server")
)

type listenerGenerator func(net.Listener) net.Listener

// Server is an HTTP proxy server.
type Server struct {
	// Allow is a function that determines whether or not to allow connections
	// from the given IP address. If unspecified, all connections are allowed.
	Allow              func(string) bool
	httpServer         http.Server
	listenerGenerators []listenerGenerator
}

// NewServer constructs a new HTTP proxy server using the given handler.
func NewServer(handler http.Handler) *Server {