ippool

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: May 11, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateIPRange

func CreateIPRange(iprange string) ([]netip.Addr, error)

create array of IP addresses from IP range for example "192.168.0-1.1-5" will converted to [192.168.0.1 192.168.0.2 192.168.0.3 192.168.0.4 192.168.0.5 192.168.1.1 192.168.1.2 192.168.1.3 192.168.1.4 192.168.1.5]

func CreateRange added in v0.2.5

func CreateRange(rng string) ([]string, error)

create range. for example srv1-3 will converted to [srv1, srv2, srv3]

Types

type Auto added in v0.2.2

type Auto struct {
}

func (*Auto) FindServer added in v0.2.2

func (m *Auto) FindServer(sIP string, p []Server) (*Server, error)

func (*Auto) Rebalance added in v0.2.2

func (m *Auto) Rebalance(p []Server)

type BalancingMethod added in v0.2.2

type BalancingMethod interface {
	FindServer(ip string, p []Server) (*Server, error)
	Rebalance([]Server)
}

interface for balancing methods

func NewBalancingMethod added in v0.2.2

func NewBalancingMethod(name string) (BalancingMethod, error)

return new balancing method

type Filter

type Filter struct {
	Name string
	// contains filtered or unexported fields
}

contains ip filters

func (*Filter) Add

func (f *Filter) Add(pool *Pool, srvpool *ServerPool)

add pool and server pool

func (*Filter) Rebalance added in v0.2.4

func (f *Filter) Rebalance()

server pool rebalance func shell

func (*Filter) SetBalancingMethod added in v0.2.2

func (f *Filter) SetBalancingMethod(bm string) error

server pool set balancing method func shell

func (*Filter) SetLogFile added in v0.2.2

func (f *Filter) SetLogFile(logDir string) error

server pool set log file func shell

func (*Filter) WhatPool

func (f *Filter) WhatPool(ip string) (*ServerPool, error)

search what pool should handle request

type HashIP added in v0.2.2

type HashIP struct {
	// contains filtered or unexported fields
}

func (*HashIP) FindServer added in v0.2.2

func (m *HashIP) FindServer(sIP string, p []Server) (*Server, error)

func (*HashIP) Rebalance added in v0.2.2

func (m *HashIP) Rebalance(p []Server)

type LeastConnections added in v0.2.2

type LeastConnections struct {
}

func (*LeastConnections) FindServer added in v0.2.2

func (m *LeastConnections) FindServer(sIP string, p []Server) (*Server, error)

func (*LeastConnections) Rebalance added in v0.2.2

func (m *LeastConnections) Rebalance(p []Server)

type None added in v0.2.2

type None struct {
}

func (*None) FindServer added in v0.2.2

func (m *None) FindServer(sIP string, p []Server) (*Server, error)

func (*None) Rebalance added in v0.2.2

func (m *None) Rebalance(p []Server)

type Pool

type Pool struct {
	Name string
	Addr []netip.Addr
	Nets []netip.Prefix
}

the struct that keep clients addresses caontain IP addresses "192.168.0.1" and IP networks "192.168.0.0/24"

func NewPool

func NewPool(ip ...string) (*Pool, error)

create and return new Pool

func (*Pool) Add

func (p *Pool) Add(ip string) error

add IP or IP range or network to the pool

func (*Pool) AddArr

func (ar *Pool) AddArr(arr []string) error

add IP or IP range or network to the pool from range of strings

func (*Pool) Contains added in v0.2.2

func (p *Pool) Contains(searchIP string) (bool, error)

check the IP addresse in pool or not return true if pool contain IP or pool contain networm what contain ip

func (*Pool) Empty added in v0.2.2

func (p *Pool) Empty() bool

type Random added in v0.2.2

type Random struct {
	// contains filtered or unexported fields
}

func (*Random) FindServer added in v0.2.2

func (m *Random) FindServer(sIP string, p []Server) (*Server, error)

func (*Random) Rebalance added in v0.2.2

func (m *Random) Rebalance(p []Server)

type RoundRobin added in v0.2.2

type RoundRobin struct {
	// contains filtered or unexported fields
}

func (*RoundRobin) FindServer added in v0.2.2

func (m *RoundRobin) FindServer(sIP string, p []Server) (*Server, error)

func (*RoundRobin) Rebalance added in v0.2.2

func (m *RoundRobin) Rebalance(p []Server)

type Server

type Server struct {
	Addr     string
	Broken   bool
	Weight   int
	Priority float64
	Fails    int
	MaxFails int

	CurrentConnectionsNumber int
	BreakTime                int
	// contains filtered or unexported fields
}

representation of the server

func NewServer

func NewServer(addr string, weight, maxFails, breakTime int) *Server

create and return new server. recive server address or domain name, server weight, maximal fail number, and break time after maximal allowed fails

func (*Server) Connect

func (s *Server) Connect(proto, port string) (net.Conn, error)

connct to the server, recieve protokol and port, return conncetion (net.Conn) or error

func (*Server) Disconnect

func (s *Server) Disconnect(conn net.Conn) error

close connection

func (*Server) ExchangeData

func (s *Server) ExchangeData(client net.Conn, server net.Conn)

create a data pipe between client and server connections. end when ends connection session

func (*Server) Fail

func (s *Server) Fail()

increment server fails quantity. if server fails == max fails, server become broken

func (*Server) SetConfig

func (s *Server) SetConfig(weight, maxFails, breakTime string) error

set new server config

func (*Server) SetLogFile added in v0.2.2

func (s *Server) SetLogFile(logDir string) error

setting server log file

type ServerPool

type ServerPool struct {
	Name    string
	Servers []Server
	Broken  []Server
	BM      BalancingMethod
}

the struct that keep servers

func NewServerPool

func NewServerPool(m map[string]interface{}) (*ServerPool, error)

create and return new ServerPool

func (*ServerPool) Add

func (p *ServerPool) Add(serverNames string, config map[string]interface{}) error

add server in servers pool

func (*ServerPool) AddFromMap

func (p *ServerPool) AddFromMap(m map[string]interface{}) error

add servers in servers pool from map

func (*ServerPool) FindServer added in v0.2.2

func (s *ServerPool) FindServer(ip string) (*Server, error)

find server in pool. for finding uses currnet balancing method

func (*ServerPool) Rebalance added in v0.2.2

func (s *ServerPool) Rebalance()

rebalance servers pool

func (*ServerPool) SetBalancingMethod added in v0.2.2

func (s *ServerPool) SetBalancingMethod(name string) error

set balancing method

func (*ServerPool) SetConfig

func (p *ServerPool) SetConfig(weight, maxFails, breakTime string) error

set new config to all servers in pool

func (*ServerPool) SetLogFile added in v0.2.2

func (s *ServerPool) SetLogFile(logDir string) error

func (*ServerPool) UpdateBroken added in v0.2.2

func (s *ServerPool) UpdateBroken()

if server is broken - it move to array of broken server. if server returns to work - it move to array of working servers

type ServerStats added in v0.2.5

type ServerStats struct {
	DataSended          uint64
	DataReceived        uint64
	AvgDataExchangeTime uint64
	AvgConnectTime      uint64
	ConnectionsNumber   uint64
}

contains server data exchange statistics

func (*ServerStats) Reset added in v0.2.5

func (s *ServerStats) Reset()

reset statistics to zero

Jump to

Keyboard shortcuts

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