net

package
v4.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2022 License: AGPL-3.0 Imports: 12 Imported by: 2

Documentation

Overview

Package net provides tools for reading IPs, available Ports, extending HTTP requests, etc.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BodyWithProgressMonitor

func BodyWithProgressMonitor(resp *http.Response, progress chan float64, done chan bool) io.Reader

BodyWithProgressMonitor creates a ProgressMonitor directly from an http.Response

func CheckPortAvailability

func CheckPortAvailability(port string) (err error)

CheckPortAvailability - check if given port is already in use. Note: The check method tries to listen on given port and closes it. It is possible to have a disconnected client in this tiny window of time.

func ExternalDomainFromRequest

func ExternalDomainFromRequest(r *net_http.Request) *url.URL

ExternalDomainFromRequest finds external URL based on request fields or headers

func GetAvailableBrokerAltPort

func GetAvailableBrokerAltPort() int

func GetAvailableHttpAltPort

func GetAvailableHttpAltPort() int

GetAvailableHttpAltPort tries to find best available port for HTTP

func GetAvailableIPs

func GetAvailableIPs() (ips []net.IP, e error)

GetAvailableIPs retrieves all outbound ips of this machine by scanning the network interfaces of this (virtual) machine

func GetAvailablePort

func GetAvailablePort() int

GetAvailablePort finds an available TCP port on which to listen to.

func GetAvailableRegistryAltPort

func GetAvailableRegistryAltPort() int

func GetOutboundIP

func GetOutboundIP() (net.IP, error)

GetOutboundIP retrieves the preferred outbound ip of this machine by simply connecting to a well known ip of the internet.

func GetTimeFromNtp

func GetTimeFromNtp() (time.Time, error)

func HostsFileLookup

func HostsFileLookup() ([]string, error)

HostsFileLookup loads host defined in /etc/hosts using jaytaylor/go-hostsfile library

func PeerAddressIsLocal

func PeerAddressIsLocal(address string) bool

PeerAddressIsLocal compares and address (can be an IP or Hostname) to the current server values

func PeerAddressesAreSameNode

func PeerAddressesAreSameNode(a1, a2 string) bool

PeerAddressesAreSameNode compares two addresses composed of multiple segments (separated by |) and check if any segments are similar

func ShouldWarnPublicBind added in v4.0.1

func ShouldWarnPublicBind() (string, []string, error)

ShouldWarnPublicBind browses all interfaces addresses and detect if some are considered public. This is used when the bind_address is not specified and servers will try to bind to all interfaces.

Types

type ProgressMonitor

type ProgressMonitor struct {
	SizeChan chan uint64
	// contains filtered or unexported fields
}

ProgressMonitor provides a TeeReader to wrap a reader and send a progress inside a dedicated channel

func NewProgressMonitor

func NewProgressMonitor(expected uint64, progress chan float64, done chan bool) *ProgressMonitor

NewProgressMonitor initialize a ProgressMonitor with the channels

func (*ProgressMonitor) Write

func (m *ProgressMonitor) Write(p []byte) (int, error)

Write implements the io.Writer interface to be used by a TeeReader

Jump to

Keyboard shortcuts

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