mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-11-25 11:05:26 +00:00
Add SwitchOptions and MaxTotalQueueSize
This commit is contained in:
parent
05b07adba2
commit
86da073226
@ -638,7 +638,7 @@ func (a *admin) getData_getSwitchQueues() admin_nodeInfo {
|
|||||||
{"queues_size", switchTable.queues.size},
|
{"queues_size", switchTable.queues.size},
|
||||||
{"highest_queues_count", switchTable.queues.maxbufs},
|
{"highest_queues_count", switchTable.queues.maxbufs},
|
||||||
{"highest_queues_size", switchTable.queues.maxsize},
|
{"highest_queues_size", switchTable.queues.maxsize},
|
||||||
{"maximum_queues_size", switch_buffer_maxSize},
|
{"maximum_queues_size", switchTable.queuetotalmaxsize},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
a.core.switchTable.doAdmin(getSwitchQueues)
|
a.core.switchTable.doAdmin(getSwitchQueues)
|
||||||
|
@ -18,6 +18,7 @@ type NodeConfig struct {
|
|||||||
IfMTU int `comment:"Maximux Transmission Unit (MTU) size for your local TUN/TAP interface.\nDefault is the largest supported size for your platform. The lowest\npossible value is 1280."`
|
IfMTU int `comment:"Maximux Transmission Unit (MTU) size for your local TUN/TAP interface.\nDefault is the largest supported size for your platform. The lowest\npossible value is 1280."`
|
||||||
SessionFirewall SessionFirewall `comment:"The session firewall controls who can send/receive network traffic\nto/from. This is useful if you want to protect this node without\nresorting to using a real firewall. This does not affect traffic\nbeing routed via this node to somewhere else. Rules are prioritised as\nfollows: blacklist, whitelist, always allow outgoing, direct, remote."`
|
SessionFirewall SessionFirewall `comment:"The session firewall controls who can send/receive network traffic\nto/from. This is useful if you want to protect this node without\nresorting to using a real firewall. This does not affect traffic\nbeing routed via this node to somewhere else. Rules are prioritised as\nfollows: blacklist, whitelist, always allow outgoing, direct, remote."`
|
||||||
TunnelRouting TunnelRouting `comment:"Allow tunneling non-Yggdrasil traffic over Yggdrasil. This effectively\nallows you to use Yggdrasil to route to, or to bridge other networks,\nsimilar to a VPN tunnel. Tunnelling works between any two nodes and\ndoes not require them to be directly peered."`
|
TunnelRouting TunnelRouting `comment:"Allow tunneling non-Yggdrasil traffic over Yggdrasil. This effectively\nallows you to use Yggdrasil to route to, or to bridge other networks,\nsimilar to a VPN tunnel. Tunnelling works between any two nodes and\ndoes not require them to be directly peered."`
|
||||||
|
SwitchOptions SwitchOptions `comment:"Advanced options for tuning the switch. Normally you will not need\nto edit these options."`
|
||||||
//Net NetConfig `comment:"Extended options for connecting to peers over other networks."`
|
//Net NetConfig `comment:"Extended options for connecting to peers over other networks."`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,3 +46,8 @@ type TunnelRouting struct {
|
|||||||
IPv4Destinations map[string]string `comment:"IPv4 CIDR subnets, mapped to the EncryptionPublicKey to which they\nshould be routed, e.g. { \"a.b.c.d/e\": \"boxpubkey\", ... }"`
|
IPv4Destinations map[string]string `comment:"IPv4 CIDR subnets, mapped to the EncryptionPublicKey to which they\nshould be routed, e.g. { \"a.b.c.d/e\": \"boxpubkey\", ... }"`
|
||||||
IPv4Sources []string `comment:"IPv4 source subnets which are allowed to be tunnelled. Unlike for\nIPv6, this option is required for bridging IPv4 traffic. Only\ntraffic with a source matching these subnets will be tunnelled."`
|
IPv4Sources []string `comment:"IPv4 source subnets which are allowed to be tunnelled. Unlike for\nIPv6, this option is required for bridging IPv4 traffic. Only\ntraffic with a source matching these subnets will be tunnelled."`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SwitchOptions contains tuning options for the switch
|
||||||
|
type SwitchOptions struct {
|
||||||
|
MaxTotalQueueSize uint64 `comment:"Maximum size of all switch queues combined."`
|
||||||
|
}
|
||||||
|
@ -105,6 +105,10 @@ func (c *Core) Start(nc *config.NodeConfig, log *log.Logger) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.switchTable.doAdmin(func() {
|
||||||
|
c.switchTable.queuetotalmaxsize = nc.SwitchOptions.MaxTotalQueueSize
|
||||||
|
})
|
||||||
|
|
||||||
c.sessions.setSessionFirewallState(nc.SessionFirewall.Enable)
|
c.sessions.setSessionFirewallState(nc.SessionFirewall.Enable)
|
||||||
c.sessions.setSessionFirewallDefaults(
|
c.sessions.setSessionFirewallDefaults(
|
||||||
nc.SessionFirewall.AllowFromDirect,
|
nc.SessionFirewall.AllowFromDirect,
|
||||||
|
@ -169,6 +169,7 @@ type switchTable struct {
|
|||||||
idleIn chan switchPort // Incoming idle notifications from peer links
|
idleIn chan switchPort // Incoming idle notifications from peer links
|
||||||
admin chan func() // Pass a lambda for the admin socket to query stuff
|
admin chan func() // Pass a lambda for the admin socket to query stuff
|
||||||
queues switch_buffers // Queues - not atomic so ONLY use through admin chan
|
queues switch_buffers // Queues - not atomic so ONLY use through admin chan
|
||||||
|
queuetotalmaxsize uint64 // Maximum combined size of queues
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initializes the switchTable struct.
|
// Initializes the switchTable struct.
|
||||||
@ -620,8 +621,6 @@ type switch_packetInfo struct {
|
|||||||
time time.Time // Timestamp of when the packet arrived
|
time time.Time // Timestamp of when the packet arrived
|
||||||
}
|
}
|
||||||
|
|
||||||
const switch_buffer_maxSize = 4 * 1048576 // Maximum 4 MB
|
|
||||||
|
|
||||||
// Used to keep track of buffered packets
|
// Used to keep track of buffered packets
|
||||||
type switch_buffer struct {
|
type switch_buffer struct {
|
||||||
packets []switch_packetInfo // Currently buffered packets, which may be dropped if it grows too large
|
packets []switch_packetInfo // Currently buffered packets, which may be dropped if it grows too large
|
||||||
@ -629,6 +628,7 @@ type switch_buffer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type switch_buffers struct {
|
type switch_buffers struct {
|
||||||
|
switchTable *switchTable
|
||||||
bufs map[string]switch_buffer // Buffers indexed by StreamID
|
bufs map[string]switch_buffer // Buffers indexed by StreamID
|
||||||
size uint64 // Total size of all buffers, in bytes
|
size uint64 // Total size of all buffers, in bytes
|
||||||
maxbufs int
|
maxbufs int
|
||||||
@ -649,7 +649,7 @@ func (b *switch_buffers) cleanup(t *switchTable) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for b.size > switch_buffer_maxSize {
|
for b.size > b.switchTable.queuetotalmaxsize {
|
||||||
// Drop a random queue
|
// Drop a random queue
|
||||||
target := rand.Uint64() % b.size
|
target := rand.Uint64() % b.size
|
||||||
var size uint64 // running total
|
var size uint64 // running total
|
||||||
@ -719,6 +719,7 @@ func (t *switchTable) handleIdle(port switchPort) bool {
|
|||||||
|
|
||||||
// The switch worker does routing lookups and sends packets to where they need to be
|
// The switch worker does routing lookups and sends packets to where they need to be
|
||||||
func (t *switchTable) doWorker() {
|
func (t *switchTable) doWorker() {
|
||||||
|
t.queues.switchTable = t
|
||||||
t.queues.bufs = make(map[string]switch_buffer) // Packets per PacketStreamID (string)
|
t.queues.bufs = make(map[string]switch_buffer) // Packets per PacketStreamID (string)
|
||||||
idle := make(map[switchPort]struct{}) // this is to deduplicate things
|
idle := make(map[switchPort]struct{}) // this is to deduplicate things
|
||||||
for {
|
for {
|
||||||
|
@ -69,6 +69,7 @@ func generateConfig(isAutoconf bool) *nodeConfig {
|
|||||||
cfg.SessionFirewall.Enable = false
|
cfg.SessionFirewall.Enable = false
|
||||||
cfg.SessionFirewall.AllowFromDirect = true
|
cfg.SessionFirewall.AllowFromDirect = true
|
||||||
cfg.SessionFirewall.AllowFromRemote = true
|
cfg.SessionFirewall.AllowFromRemote = true
|
||||||
|
cfg.SwitchOptions.MaxTotalQueueSize = 4 * 1048576
|
||||||
|
|
||||||
return &cfg
|
return &cfg
|
||||||
}
|
}
|
||||||
|
@ -216,8 +216,8 @@ func main() {
|
|||||||
fmt.Printf("Highest queue size: %d bytes\n", uint(highestqueuesize))
|
fmt.Printf("Highest queue size: %d bytes\n", uint(highestqueuesize))
|
||||||
}
|
}
|
||||||
if m, ok := v["maximum_queues_size"].(float64); ok {
|
if m, ok := v["maximum_queues_size"].(float64); ok {
|
||||||
fmt.Printf("Maximum queue size: %d bytes\n", uint(maximumqueuesize))
|
|
||||||
maximumqueuesize = m
|
maximumqueuesize = m
|
||||||
|
fmt.Printf("Maximum queue size: %d bytes\n", uint(maximumqueuesize))
|
||||||
}
|
}
|
||||||
if queues, ok := v["queues"].([]interface{}); ok {
|
if queues, ok := v["queues"].([]interface{}); ok {
|
||||||
if len(queues) != 0 {
|
if len(queues) != 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user