Documentation ¶
Index ¶
- Constants
- Variables
- func ChangeMaxPayloadSize(newMaxPayloadSize int)
- func Copy(dst io.Writer, src io.Reader) (written int64, err error)
- func DebugSummary(buf []byte, max int) string
- func EscapeBytes(buf []byte) string
- func GeneratePayload(payloadFilePath string, payloadSize int, payload string) []byte
- func GenerateRandomPayload(payloadSize int) []byte
- func GetPort(lAddr net.Addr) string
- func GetUniqueUnixDomainPath(prefix string) string
- func Listen(name string, port string) (net.Listener, net.Addr)
- func NetCat(dest string, in io.Reader, out io.Writer, stopOnEOF bool) error
- func NormalizeHostPort(inputPort string, addr net.Addr) string
- func NormalizePort(port string) string
- func Proxy(port string, dest net.Addr) net.Addr
- func ProxyToDestination(listenPort string, destination string) net.Addr
- func ReadFileForPayload(payloadFilePath string) ([]byte, error)
- func Resolve(host string, port string) (*net.TCPAddr, error)
- func ResolveDestination(dest string) (*net.TCPAddr, error)
- func SetSocketBuffers(socket net.Conn, readBufferSize, writeBufferSize int)
- func SmallReadUntil(r io.Reader, stopByte byte, max int) ([]byte, bool, error)
- func TCPEchoServer(name string, port string) net.Addr
- func TCPResolveDestination(dest string) (*net.TCPAddr, error)
- func UDPEchoServer(name string, port string, async bool) net.Addr
- func UDPListen(name string, port string) (*net.UDPConn, net.Addr)
- func UDPNetCat(dest string, in io.Reader, out io.Writer, stopOnEOF bool) error
- func UDPResolveDestination(dest string) (*net.UDPAddr, error)
- func ValidatePayloadSize(size *int)
- type HostPortAddr
Constants ¶
const ( // DefaultGRPCPort is the Fortio gRPC server default port number. DefaultGRPCPort = "8079" // StandardHTTPPort is the Standard http port number. StandardHTTPPort = "80" // StandardHTTPSPort is the Standard https port number. StandardHTTPSPort = "443" // PrefixHTTP is a constant value for representing http protocol that can be added prefix of url. PrefixHTTP = "http://" // PrefixHTTPS is a constant value for representing secure http protocol that can be added prefix of url. PrefixHTTPS = "https://" // POST is a constant value that indicates http method as post. POST = "POST" // GET is a constant value that indicates http method as get. GET = "GET" // UnixDomainSocket type for network addresses. UnixDomainSocket = "unix" )
const UDPPrefix = "udp://"
UDPPrefix is the prefix that given to NetCat switches to UDP from TCP(/unix domain) socket type.
Variables ¶
var ( // KILOBYTE is a constant for kilobyte (ie 1024). KILOBYTE = 1024 // MaxPayloadSize is the maximum size of payload to be generated by the // EchoHandler size= argument. In bytes. MaxPayloadSize = 256 * KILOBYTE // Payload that is returned during echo call. Payload []byte )
var ErrNilDestination = fmt.Errorf("nil destination")
ErrNilDestination returned when trying to proxy to a nil address.
Functions ¶
func ChangeMaxPayloadSize ¶ added in v1.1.0
func ChangeMaxPayloadSize(newMaxPayloadSize int)
ChangeMaxPayloadSize is used to change max payload size and fill it with pseudorandom content.
func DebugSummary ¶ added in v1.11.3
DebugSummary returns a string with the size and escaped first max/2 and last max/2 bytes of a buffer (or the whole escaped buffer if small enough).
func EscapeBytes ¶ added in v1.11.3
EscapeBytes returns printable string. Same as %q format without the surrounding/extra "".
func GeneratePayload ¶ added in v1.1.0
GeneratePayload generates a payload with given inputs. First tries filePath, then random payload, at last payload.
func GenerateRandomPayload ¶ added in v1.1.0
GenerateRandomPayload generates a random payload with given input size.
func GetPort ¶ added in v1.1.0
GetPort extracts the port for TCP sockets and the path for unix domain sockets.
func GetUniqueUnixDomainPath ¶ added in v1.1.0
GetUniqueUnixDomainPath returns a path to be used for unix domain socket.
func Listen ¶ added in v0.8.0
Listen returns a listener for the port. Port can be a port or a bind address and a port (e.g. "8080" or "[::1]:8080"...). If the port component is 0 a free port will be returned by the system. If the port is a pathname (contains a /) a unix domain socket listener will be used instead of regular tcp socket. This logs critical on error and returns nil (is meant for servers that must start).
func NetCat ¶ added in v1.8.0
NetCat connects to the destination and reads from in, sends to the socket, and write what it reads from the socket to out. if the destination starts with udp:// UDP is used otherwise TCP.
func NormalizeHostPort ¶ added in v1.0.0
NormalizeHostPort generates host:port string for the address or uses localhost instead of [::] when the original port binding input didn't specify an address.
func NormalizePort ¶
NormalizePort parses port and returns host:port if port is in the form of host:port already or :port if port is only a port (doesn't contain :).
func ProxyToDestination ¶ added in v0.8.0
ProxyToDestination opens a proxy from the listenPort (or addr:port or unix domain socket path) and forwards all traffic to destination (host:port).
func ReadFileForPayload ¶ added in v1.1.0
ReadFileForPayload reads the file from given input path.
func ResolveDestination ¶ added in v0.8.0
ResolveDestination returns the TCP address of the "host:port" suitable for net.Dial. nil in case of errors. Backward compatible name (1.12 and prior) for TCPResolveDestination.
func SetSocketBuffers ¶ added in v1.8.0
SetSocketBuffers sets the read and write buffer size of the socket. Also sets tcp SetNoDelay().
func SmallReadUntil ¶ added in v1.6.4
SmallReadUntil will read one byte at a time until stopByte is found and up to max bytes total. Returns what was read (without the stop byte when found), whether the stop byte was found, whether an error occurred (eof...). Because we read one by one directly (no buffer) this should only be used for short variable length preamble type read.
func TCPEchoServer ¶ added in v1.8.0
TCPEchoServer starts a TCP Echo Server on given port, name is for logging.
func TCPResolveDestination ¶ added in v1.14.0
TCPResolveDestination returns the TCP address of the "host:port" suitable for net.Dial. nil in case of errors.
func UDPEchoServer ¶ added in v1.14.0
UDPEchoServer starts a UDP Echo Server on given port, name is for logging. if async flag is true will spawn go routines to reply otherwise single go routine.
func UDPResolveDestination ¶ added in v1.14.0
UDPResolveDestination returns the UDP address of the "host:port" suitable for net.Dial. nil and the error in case of errors.
func ValidatePayloadSize ¶ added in v1.1.0
func ValidatePayloadSize(size *int)
ValidatePayloadSize compares input size with MaxPayLoadSize. If size exceeds the MaxPayloadSize size will set to MaxPayLoadSize.
Types ¶
type HostPortAddr ¶ added in v1.14.0
HostPortAddr is the missing base. IPAddr and UDPAddr are actually the same but don't share a base (!)
func ResolveByProto ¶ added in v1.14.0
func ResolveByProto(host string, port string, proto string) (*HostPortAddr, error)
ResolveByProto returns the address of the host,port suitable for net.Dial. nil in case of errors. works for both "tcp" and "udp" proto.
func ResolveDestinationInternal ¶ added in v1.14.0
func ResolveDestinationInternal(dest string, expected string, unexpected string) (*HostPortAddr, error)
ResolveDestinationInternal returns the address of the "host:port" suitable for net.Dial. nil in case of errors. Works for both TCP and UDP but proto must be passed as expected == tcp:// or udp:// and the other as unexpected.
func (*HostPortAddr) String ¶ added in v1.14.0
func (hpa *HostPortAddr) String() string