本文整理汇总了Golang中github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common.ContextError函数的典型用法代码示例。如果您正苦于以下问题:Golang ContextError函数的具体用法?Golang ContextError怎么用?Golang ContextError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ContextError函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: connectedAPIRequestHandler
// connectedAPIRequestHandler implements the "connected" API request.
// Clients make the connected request once a tunnel connection has been
// established and at least once per day. The last_connected input value,
// which should be a connected_timestamp output from a previous connected
// response, is used to calculate unique user stats.
func connectedAPIRequestHandler(
support *SupportServices,
geoIPData GeoIPData,
params requestJSONObject) ([]byte, error) {
err := validateRequestParams(support, params, connectedRequestParams)
if err != nil {
return nil, common.ContextError(err)
}
log.LogRawFieldsWithTimestamp(
getRequestLogFields(
support,
"connected",
geoIPData,
params,
connectedRequestParams))
connectedResponse := common.ConnectedResponse{
ConnectedTimestamp: common.TruncateTimestampToHour(common.GetCurrentTimestamp()),
}
responsePayload, err := json.Marshal(connectedResponse)
if err != nil {
return nil, common.ContextError(err)
}
return responsePayload, nil
}
开发者ID:Psiphon-Labs,项目名称:psiphon-tunnel-core,代码行数:34,代码来源:api.go
示例2: tunneledLookupIP
// tunneledLookupIP resolves a split tunnel candidate hostname with a tunneled
// DNS request.
func tunneledLookupIP(
dnsServerAddress string, dnsTunneler Tunneler, host string) (addr net.IP, ttl time.Duration, err error) {
ipAddr := net.ParseIP(host)
if ipAddr != nil {
// maxDuration from golang.org/src/time/time.go
return ipAddr, time.Duration(1<<63 - 1), nil
}
// dnsServerAddress must be an IP address
ipAddr = net.ParseIP(dnsServerAddress)
if ipAddr == nil {
return nil, 0, common.ContextError(errors.New("invalid IP address"))
}
// Dial's alwaysTunnel is set to true to ensure this connection
// is tunneled (also ensures this code path isn't circular).
// Assumes tunnel dialer conn configures timeouts and interruptibility.
conn, err := dnsTunneler.Dial(fmt.Sprintf(
"%s:%d", dnsServerAddress, DNS_PORT), true, nil)
if err != nil {
return nil, 0, common.ContextError(err)
}
ipAddrs, ttls, err := ResolveIP(host, conn)
if err != nil {
return nil, 0, common.ContextError(err)
}
if len(ipAddrs) < 1 {
return nil, 0, common.ContextError(errors.New("no IP address"))
}
return ipAddrs[0], ttls[0], nil
}
开发者ID:adamkruger,项目名称:psiphon-tunnel-core,代码行数:37,代码来源:splitTunnel.go
示例3: encryptAESCBC
// Encrypt plaintext with AES in CBC mode.
func encryptAESCBC(plaintext []byte) ([]byte, []byte, []byte, error) {
// CBC mode works on blocks so plaintexts need to be padded to the
// next whole block (https://tools.ietf.org/html/rfc5246#section-6.2.3.2).
plaintext = AddPKCS7Padding(plaintext, aes.BlockSize)
ciphertext := make([]byte, len(plaintext))
iv, err := common.MakeSecureRandomBytes(aes.BlockSize)
if err != nil {
return nil, nil, nil, err
}
key, err := common.MakeSecureRandomBytes(aes.BlockSize)
if err != nil {
return nil, nil, nil, common.ContextError(err)
}
block, err := aes.NewCipher(key)
if err != nil {
return nil, nil, nil, common.ContextError(err)
}
mode := cipher.NewCBCEncrypter(block, iv)
mode.CryptBlocks(ciphertext, plaintext)
return iv, key, ciphertext, nil
}
开发者ID:Psiphon-Labs,项目名称:psiphon-tunnel-core,代码行数:27,代码来源:feedback.go
示例4: NewServerContext
// NewServerContext makes the tunnelled handshake request to the Psiphon server
// and returns a ServerContext struct for use with subsequent Psiphon server API
// requests (e.g., periodic connected and status requests).
func NewServerContext(tunnel *Tunnel, sessionId string) (*ServerContext, error) {
// For legacy servers, set up psiphonHttpsClient for
// accessing the Psiphon API via the web service.
var psiphonHttpsClient *http.Client
if !tunnel.serverEntry.SupportsSSHAPIRequests() ||
tunnel.config.TargetApiProtocol == common.PSIPHON_WEB_API_PROTOCOL {
var err error
psiphonHttpsClient, err = makePsiphonHttpsClient(tunnel)
if err != nil {
return nil, common.ContextError(err)
}
}
serverContext := &ServerContext{
sessionId: sessionId,
tunnelNumber: atomic.AddInt64(&nextTunnelNumber, 1),
tunnel: tunnel,
psiphonHttpsClient: psiphonHttpsClient,
}
err := serverContext.doHandshakeRequest()
if err != nil {
return nil, common.ContextError(err)
}
return serverContext, nil
}
开发者ID:Psiphon-Labs,项目名称:psiphon-tunnel-core,代码行数:32,代码来源:serverApi.go
示例5: HandleOSLRequest
func HandleOSLRequest(
tunnelOwner TunnelOwner, tunnel *Tunnel, payload []byte) error {
var oslRequest protocol.OSLRequest
err := json.Unmarshal(payload, &oslRequest)
if err != nil {
return common.ContextError(err)
}
if oslRequest.ClearLocalSLOKs {
DeleteSLOKs()
}
seededNewSLOK := false
for _, slok := range oslRequest.SeedPayload.SLOKs {
duplicate, err := SetSLOK(slok.ID, slok.Key)
if err != nil {
// TODO: return error to trigger retry?
NoticeAlert("SetSLOK failed: %s", common.ContextError(err))
} else if !duplicate {
seededNewSLOK = true
}
if tunnel.config.EmitSLOKs {
NoticeSLOKSeeded(base64.StdEncoding.EncodeToString(slok.ID), duplicate)
}
}
if seededNewSLOK {
tunnelOwner.SignalSeededNewSLOK()
}
return nil
}
开发者ID:adamkruger,项目名称:psiphon-tunnel-core,代码行数:35,代码来源:serverApi.go
示例6: parseResolveConf
func parseResolveConf(filename string) (net.IP, error) {
file, err := os.Open(filename)
if err != nil {
return nil, common.ContextError(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
if strings.HasPrefix(line, ";") || strings.HasPrefix(line, "#") {
continue
}
fields := strings.Fields(line)
if len(fields) == 2 && fields[0] == "nameserver" {
// TODO: parseResolverAddress will fail when the nameserver
// is not an IP address. It may be a domain name. To support
// this case, should proceed to the next "nameserver" line.
return parseResolver(fields[1])
}
}
if err := scanner.Err(); err != nil {
return nil, common.ContextError(err)
}
return nil, common.ContextError(errors.New("nameserver not found"))
}
开发者ID:Psiphon-Labs,项目名称:psiphon-tunnel-core,代码行数:26,代码来源:dns.go
示例7: validateRequestParams
func validateRequestParams(
support *SupportServices,
params requestJSONObject,
expectedParams []requestParamSpec) error {
for _, expectedParam := range expectedParams {
value := params[expectedParam.name]
if value == nil {
if expectedParam.flags&requestParamOptional != 0 {
continue
}
return common.ContextError(
fmt.Errorf("missing param: %s", expectedParam.name))
}
var err error
if expectedParam.flags&requestParamArray != 0 {
err = validateStringArrayRequestParam(support, expectedParam, value)
} else {
err = validateStringRequestParam(support, expectedParam, value)
}
if err != nil {
return common.ContextError(err)
}
}
return nil
}
开发者ID:Psiphon-Labs,项目名称:psiphon-tunnel-core,代码行数:27,代码来源:api.go
示例8: NewSupportServices
// NewSupportServices initializes a new SupportServices.
func NewSupportServices(config *Config) (*SupportServices, error) {
trafficRulesSet, err := NewTrafficRulesSet(config.TrafficRulesFilename)
if err != nil {
return nil, common.ContextError(err)
}
psinetDatabase, err := psinet.NewDatabase(config.PsinetDatabaseFilename)
if err != nil {
return nil, common.ContextError(err)
}
geoIPService, err := NewGeoIPService(
config.GeoIPDatabaseFilenames, config.DiscoveryValueHMACKey)
if err != nil {
return nil, common.ContextError(err)
}
dnsResolver, err := NewDNSResolver(config.DNSResolverIPAddress)
if err != nil {
return nil, common.ContextError(err)
}
return &SupportServices{
Config: config,
TrafficRulesSet: trafficRulesSet,
PsinetDatabase: psinetDatabase,
GeoIPService: geoIPService,
DNSResolver: dnsResolver,
}, nil
}
开发者ID:Psiphon-Labs,项目名称:psiphon-tunnel-core,代码行数:31,代码来源:services.go
示例9: unpackRemoteServerListFile
// unpackRemoteServerListFile reads a file that contains a
// zlib compressed authenticated data package, validates
// the package, and returns the payload.
func unpackRemoteServerListFile(
config *Config, filename string) (string, error) {
fileReader, err := os.Open(filename)
if err != nil {
return "", common.ContextError(err)
}
defer fileReader.Close()
zlibReader, err := zlib.NewReader(fileReader)
if err != nil {
return "", common.ContextError(err)
}
dataPackage, err := ioutil.ReadAll(zlibReader)
zlibReader.Close()
if err != nil {
return "", common.ContextError(err)
}
payload, err := common.ReadAuthenticatedDataPackage(
dataPackage, config.RemoteServerListSignaturePublicKey)
if err != nil {
return "", common.ContextError(err)
}
return payload, nil
}
开发者ID:adamkruger,项目名称:psiphon-tunnel-core,代码行数:31,代码来源:remoteServerList.go
示例10: scanServerEntries
func scanServerEntries(scanner func(*protocol.ServerEntry)) error {
err := singleton.db.View(func(tx *bolt.Tx) error {
bucket := tx.Bucket([]byte(serverEntriesBucket))
cursor := bucket.Cursor()
for key, value := cursor.First(); key != nil; key, value = cursor.Next() {
serverEntry := new(protocol.ServerEntry)
err := json.Unmarshal(value, serverEntry)
if err != nil {
// In case of data corruption or a bug causing this condition,
// do not stop iterating.
NoticeAlert("scanServerEntries: %s", common.ContextError(err))
continue
}
scanner(serverEntry)
}
return nil
})
if err != nil {
return common.ContextError(err)
}
return nil
}
开发者ID:adamkruger,项目名称:psiphon-tunnel-core,代码行数:26,代码来源:dataStore.go
示例11: NewDatabase
// NewDatabase initializes a Database, calling Reload on the specified
// filename.
func NewDatabase(filename string) (*Database, error) {
database := &Database{}
database.ReloadableFile = common.NewReloadableFile(
filename,
func(filename string) error {
psinetJSON, err := ioutil.ReadFile(filename)
if err != nil {
// On error, state remains the same
return common.ContextError(err)
}
err = json.Unmarshal(psinetJSON, &database)
if err != nil {
// On error, state remains the same
// (Unmarshal first validates the provided
// JOSN and then populates the interface)
return common.ContextError(err)
}
return nil
})
_, err := database.Reload()
if err != nil {
return nil, common.ContextError(err)
}
return database, nil
}
开发者ID:geebee,项目名称:psiphon-tunnel-core,代码行数:31,代码来源:psinet.go
示例12: InitLogging
// InitLogging configures a logger according to the specified
// config params. If not called, the default logger set by the
// package init() is used.
// Concurrenty note: should only be called from the main
// goroutine.
func InitLogging(config *Config) error {
level, err := logrus.ParseLevel(config.LogLevel)
if err != nil {
return common.ContextError(err)
}
logWriter := os.Stderr
if config.LogFilename != "" {
logWriter, err = os.OpenFile(
config.LogFilename, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0666)
if err != nil {
return common.ContextError(err)
}
}
log = &ContextLogger{
&logrus.Logger{
Out: logWriter,
Formatter: &CustomJSONFormatter{},
Level: level,
},
}
return nil
}
开发者ID:Psiphon-Labs,项目名称:psiphon-tunnel-core,代码行数:32,代码来源:log.go
示例13: readSshPacket
func readSshPacket(
conn net.Conn, deobfuscate func([]byte)) ([]byte, bool, error) {
prefix := make([]byte, SSH_PACKET_PREFIX_LENGTH)
_, err := io.ReadFull(conn, prefix)
if err != nil {
return nil, false, common.ContextError(err)
}
deobfuscate(prefix)
packetLength, _, payloadLength, messageLength := getSshPacketPrefix(prefix)
if packetLength > SSH_MAX_PACKET_LENGTH {
return nil, false, common.ContextError(errors.New("ssh packet length too large"))
}
readBuffer := make([]byte, messageLength)
copy(readBuffer, prefix)
_, err = io.ReadFull(conn, readBuffer[len(prefix):])
if err != nil {
return nil, false, common.ContextError(err)
}
deobfuscate(readBuffer[len(prefix):])
isMsgNewKeys := false
if payloadLength > 0 {
packetType := int(readBuffer[SSH_PACKET_PREFIX_LENGTH])
if packetType == SSH_MSG_NEWKEYS {
isMsgNewKeys = true
}
}
return readBuffer, isMsgNewKeys, nil
}
开发者ID:Psiphon-Labs,项目名称:psiphon-tunnel-core,代码行数:29,代码来源:obfuscatedSshConn.go
示例14: NewClientObfuscator
// NewClientObfuscator creates a new Obfuscator, staging a seed message to be
// sent to the server (by the caller) and initializing stream ciphers to
// obfuscate data.
func NewClientObfuscator(
config *ObfuscatorConfig) (obfuscator *Obfuscator, err error) {
seed, err := common.MakeSecureRandomBytes(OBFUSCATE_SEED_LENGTH)
if err != nil {
return nil, common.ContextError(err)
}
clientToServerCipher, serverToClientCipher, err := initObfuscatorCiphers(seed, config)
if err != nil {
return nil, common.ContextError(err)
}
maxPadding := OBFUSCATE_MAX_PADDING
if config.MaxPadding > 0 {
maxPadding = config.MaxPadding
}
seedMessage, err := makeSeedMessage(maxPadding, seed, clientToServerCipher)
if err != nil {
return nil, common.ContextError(err)
}
return &Obfuscator{
seedMessage: seedMessage,
clientToServerCipher: clientToServerCipher,
serverToClientCipher: serverToClientCipher}, nil
}
开发者ID:Psiphon-Labs,项目名称:psiphon-tunnel-core,代码行数:31,代码来源:obfuscator.go
示例15: NewTrafficRulesSet
// NewTrafficRulesSet initializes a TrafficRulesSet with
// the rules data in the specified config file.
func NewTrafficRulesSet(filename string) (*TrafficRulesSet, error) {
set := &TrafficRulesSet{}
set.ReloadableFile = common.NewReloadableFile(
filename,
func(filename string) error {
configJSON, err := ioutil.ReadFile(filename)
if err != nil {
// On error, state remains the same
return common.ContextError(err)
}
var newSet TrafficRulesSet
err = json.Unmarshal(configJSON, &newSet)
if err != nil {
return common.ContextError(err)
}
err = newSet.Validate()
if err != nil {
return common.ContextError(err)
}
// Modify actual traffic rules only after validation
set.DefaultRules = newSet.DefaultRules
set.FilteredRules = newSet.FilteredRules
return nil
})
_, err := set.Reload()
if err != nil {
return nil, common.ContextError(err)
}
return set, nil
}
开发者ID:Psiphon-Labs,项目名称:psiphon-tunnel-core,代码行数:36,代码来源:trafficRules.go
示例16: initObfuscatorCiphers
func initObfuscatorCiphers(
seed []byte, config *ObfuscatorConfig) (*rc4.Cipher, *rc4.Cipher, error) {
clientToServerKey, err := deriveKey(seed, []byte(config.Keyword), []byte(OBFUSCATE_CLIENT_TO_SERVER_IV))
if err != nil {
return nil, nil, common.ContextError(err)
}
serverToClientKey, err := deriveKey(seed, []byte(config.Keyword), []byte(OBFUSCATE_SERVER_TO_CLIENT_IV))
if err != nil {
return nil, nil, common.ContextError(err)
}
clientToServerCipher, err := rc4.NewCipher(clientToServerKey)
if err != nil {
return nil, nil, common.ContextError(err)
}
serverToClientCipher, err := rc4.NewCipher(serverToClientKey)
if err != nil {
return nil, nil, common.ContextError(err)
}
return clientToServerCipher, serverToClientCipher, nil
}
开发者ID:Psiphon-Labs,项目名称:psiphon-tunnel-core,代码行数:25,代码来源:obfuscator.go
示例17: Write
// Write writes data to the connection.
// net.Conn Deadlines are ignored. net.Conn concurrency semantics are supported.
func (meek *MeekConn) Write(buffer []byte) (n int, err error) {
if meek.closed() {
return 0, common.ContextError(errors.New("meek connection is closed"))
}
// Repeats until all n bytes are written
n = len(buffer)
for len(buffer) > 0 {
// Block until there is capacity in the send buffer
var sendBuffer *bytes.Buffer
select {
case sendBuffer = <-meek.emptySendBuffer:
case sendBuffer = <-meek.partialSendBuffer:
case <-meek.broadcastClosed:
return 0, common.ContextError(errors.New("meek connection has closed"))
}
writeLen := MAX_SEND_PAYLOAD_LENGTH - sendBuffer.Len()
if writeLen > 0 {
if writeLen > len(buffer) {
writeLen = len(buffer)
}
_, err = sendBuffer.Write(buffer[:writeLen])
buffer = buffer[writeLen:]
}
meek.replaceSendBuffer(sendBuffer)
}
return n, err
}
开发者ID:adamkruger,项目名称:psiphon-tunnel-core,代码行数:29,代码来源:meekConn.go
示例18: DecodeServerEntry
// DecodeServerEntry extracts server entries from the encoding
// used by remote server lists and Psiphon server handshake requests.
//
// The resulting ServerEntry.LocalSource is populated with serverEntrySource,
// which should be one of SERVER_ENTRY_SOURCE_EMBEDDED, SERVER_ENTRY_SOURCE_REMOTE,
// SERVER_ENTRY_SOURCE_DISCOVERY, SERVER_ENTRY_SOURCE_TARGET.
// ServerEntry.LocalTimestamp is populated with the provided timestamp, which
// should be a RFC 3339 formatted string. These local fields are stored with the
// server entry and reported to the server as stats (a coarse granularity timestamp
// is reported).
func DecodeServerEntry(
encodedServerEntry, timestamp,
serverEntrySource string) (serverEntry *ServerEntry, err error) {
hexDecodedServerEntry, err := hex.DecodeString(encodedServerEntry)
if err != nil {
return nil, common.ContextError(err)
}
// Skip past legacy format (4 space delimited fields) and just parse the JSON config
fields := bytes.SplitN(hexDecodedServerEntry, []byte(" "), 5)
if len(fields) != 5 {
return nil, common.ContextError(errors.New("invalid encoded server entry"))
}
serverEntry = new(ServerEntry)
err = json.Unmarshal(fields[4], &serverEntry)
if err != nil {
return nil, common.ContextError(err)
}
// NOTE: if the source JSON happens to have values in these fields, they get clobbered.
serverEntry.LocalSource = serverEntrySource
serverEntry.LocalTimestamp = timestamp
return serverEntry, nil
}
开发者ID:Psiphon-Labs,项目名称:psiphon-tunnel-core,代码行数:37,代码来源:serverEntry.go
示例19: GetInterfaceIPAddress
// Take in an interface name ("lo", "eth0", "any") passed from either
// a config setting, by using the -listenInterface flag on client or
// -interface flag on server from the command line and return the IP
// address associated with it.
// If no interface is provided use the default loopback interface (127.0.0.1).
// If "any" is passed then listen on 0.0.0.0 for client (invalid with server)
func GetInterfaceIPAddress(listenInterface string) (string, error) {
var ip net.IP
if listenInterface == "" {
ip = net.ParseIP("127.0.0.1")
return ip.String(), nil
} else if listenInterface == "any" {
ip = net.ParseIP("0.0.0.0")
return ip.String(), nil
} else {
availableInterfaces, err := net.InterfaceByName(listenInterface)
if err != nil {
return "", common.ContextError(err)
}
addrs, err := availableInterfaces.Addrs()
if err != nil {
return "", common.ContextError(err)
}
for _, addr := range addrs {
iptype := addr.(*net.IPNet)
if iptype == nil {
continue
}
// TODO: IPv6 support
ip = iptype.IP.To4()
if ip == nil {
continue
}
return ip.String(), nil
}
}
return "", common.ContextError(errors.New("Could not find IP address of specified interface"))
}
开发者ID:Psiphon-Labs,项目名称:psiphon-tunnel-core,代码行数:41,代码来源:networkInterface.go
示例20: MakeTunneledHttpClient
// MakeTunneledHttpClient returns a net/http.Client which is
// configured to use custom dialing features including tunneled
// dialing and, optionally, UseTrustedCACertificatesForStockTLS.
// Unlike MakeUntunneledHttpsClient and makePsiphonHttpsClient,
// This http.Client uses stock TLS and no scheme transformation
// hack is required.
func MakeTunneledHttpClient(
config *Config,
tunnel *Tunnel,
requestTimeout time.Duration) (*http.Client, error) {
tunneledDialer := func(_, addr string) (conn net.Conn, err error) {
return tunnel.sshClient.Dial("tcp", addr)
}
transport := &http.Transport{
Dial: tunneledDialer,
}
if config.UseTrustedCACertificatesForStockTLS {
if config.TrustedCACertificatesFilename == "" {
return nil, common.ContextError(errors.New(
"UseTrustedCACertificatesForStockTLS requires TrustedCACertificatesFilename"))
}
rootCAs := x509.NewCertPool()
certData, err := ioutil.ReadFile(config.TrustedCACertificatesFilename)
if err != nil {
return nil, common.ContextError(err)
}
rootCAs.AppendCertsFromPEM(certData)
transport.TLSClientConfig = &tls.Config{RootCAs: rootCAs}
}
return &http.Client{
Transport: transport,
Timeout: requestTimeout,
}, nil
}
开发者ID:Psiphon-Labs,项目名称:psiphon-tunnel-core,代码行数:38,代码来源:net.go
注:本文中的github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common.ContextError函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论