net

package
v0.0.0-...-7ee7fde Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2020 License: Apache-2.0 Imports: 12 Imported by: 4

Documentation

Overview

Copyright (c) 2018-2020. The asimov developers Copyright (c) 2013-2017 The btcsuite developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Copyright (c) 2018-2020. The asimov developers Copyright (c) 2013-2017 The btcsuite developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Copyright (c) 2018-2020. The asimov developers Copyright (c) 2013-2017 The btcsuite developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Copyright (c) 2018-2020. The asimov developers Copyright (c) 2013-2017 The btcsuite developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTorInvalidAddressResponse indicates an invalid address was
	// returned by the Tor DNS resolver.
	ErrTorInvalidAddressResponse = errors.New("invalid address response")

	// ErrTorInvalidProxyResponse indicates the Tor proxy returned a
	// response in an unexpected format.
	ErrTorInvalidProxyResponse = errors.New("invalid proxy response")

	// ErrTorUnrecognizedAuthMethod indicates the authentication method
	// provided is not recognized.
	ErrTorUnrecognizedAuthMethod = errors.New("invalid proxy authentication method")
)

Functions

func DirectionString

func DirectionString(inbound bool) string

DirectionString is a helper function that returns a string that represents the direction of a connection (inbound or outbound).

func NormalizeAddress

func NormalizeAddress(addr, defaultPort string) string

normalizeAddress returns addr with the passed default port appended if there is not already a port specified.

func NormalizeAddresses

func NormalizeAddresses(addrs []string, defaultPort string) []string

normalizeAddresses returns a new slice with all the passed peer addresses normalized with the given default port, and all duplicates removed.

func PickNoun

func PickNoun(n uint64, singular, plural string) string

PickNoun returns the singular or plural form of a noun depending on the count n.

Types

type NAT

type NAT interface {
	// Get the external address from outside the NAT.
	GetExternalAddress() (addr net.IP, err error)
	// Add a port mapping for protocol ("udp" or "tcp") from external port to
	// internal port with description lasting for timeout.
	AddPortMapping(protocol string, externalPort, internalPort int, description string, timeout int) (mappedExternalPort int, err error)
	// Remove a previously added port mapping from external port to
	// internal port.
	DeletePortMapping(protocol string, externalPort, internalPort int) (err error)
}

NAT is an interface representing a NAT traversal options for example UPNP or NAT-PMP. It provides methods to query and manipulate this traversal to allow access to services.

func Discover

func Discover() (nat NAT, err error)

Discover searches the local network for a UPnP router returning a NAT for the network if so, nil if not.

type NetAdapter

type NetAdapter interface {
	// Connects to a server, with default connect timeout 30s
	// @params
	//   addr: server address in net type
	// @return
	//   Conn: a successful connection
	//   error: some detail information when connect failed.
	DialTimeout(addr net.Addr) (net.Conn, error)

	// Lookup resolves the IP of the given host using the correct DNS lookup
	// function depending on the configuration options.  For example, addresses will
	// be resolved using tor when the --proxy flag was specified unless --noonion
	// was also specified in which case the normal system DNS resolver will be used.
	//
	// Any attempt to resolve a tor address (.onion) will return an error since they
	// are not intended to be resolved outside of the tor proxy.
	Lookup(host string) ([]net.IP, error)

	// whether it support onion
	SupportOnion() bool
}

NetAdapter is an interface representing a Net adapter traversal options for example Onion or Proxy. It provides methods to connect to server and lookup host.

func NewNetAdapter

func NewNetAdapter(proxy, user, pass string, onionProxy, onionUser, onionPass string,
	torIsolation bool, noOnion bool) NetAdapter

NewNetAdapter create a new fnetAdapter instance. Setup dial and DNS resolution (lookup) functions depending on the specified options. The default is to use the standard net.DialTimeout function as well as the system DNS resolver. When a proxy is specified, the dial function is set to the proxy specific dial function and the lookup is set to use tor (unless --noonion is specified in which case the system DNS resolver is used).

Jump to

Keyboard shortcuts

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