repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
google/seesaw
common/seesaw/util.go
Copy
func (h *HAConfig) Copy(c *HAConfig) { h.Enabled = c.Enabled h.LocalAddr = copyIP(c.LocalAddr) h.RemoteAddr = copyIP(c.RemoteAddr) h.Priority = c.Priority h.VRID = c.VRID }
go
func (h *HAConfig) Copy(c *HAConfig) { h.Enabled = c.Enabled h.LocalAddr = copyIP(c.LocalAddr) h.RemoteAddr = copyIP(c.RemoteAddr) h.Priority = c.Priority h.VRID = c.VRID }
[ "func", "(", "h", "*", "HAConfig", ")", "Copy", "(", "c", "*", "HAConfig", ")", "{", "h", ".", "Enabled", "=", "c", ".", "Enabled", "\n", "h", ".", "LocalAddr", "=", "copyIP", "(", "c", ".", "LocalAddr", ")", "\n", "h", ".", "RemoteAddr", "=", "copyIP", "(", "c", ".", "RemoteAddr", ")", "\n", "h", ".", "Priority", "=", "c", ".", "Priority", "\n", "h", ".", "VRID", "=", "c", ".", "VRID", "\n", "}" ]
// Copy deep copies from the given Seesaw HAConfig.
[ "Copy", "deep", "copies", "from", "the", "given", "Seesaw", "HAConfig", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L142-L148
train
google/seesaw
common/seesaw/util.go
Clone
func (h *HAConfig) Clone() *HAConfig { var c HAConfig c.Copy(h) return &c }
go
func (h *HAConfig) Clone() *HAConfig { var c HAConfig c.Copy(h) return &c }
[ "func", "(", "h", "*", "HAConfig", ")", "Clone", "(", ")", "*", "HAConfig", "{", "var", "c", "HAConfig", "\n", "c", ".", "Copy", "(", "h", ")", "\n", "return", "&", "c", "\n", "}" ]
// Clone creates an identical copy of the given Seesaw HAConfig.
[ "Clone", "creates", "an", "identical", "copy", "of", "the", "given", "Seesaw", "HAConfig", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L151-L155
train
google/seesaw
common/seesaw/util.go
Equal
func (h *HAConfig) Equal(other *HAConfig) bool { return h.Enabled == other.Enabled && h.LocalAddr.Equal(other.LocalAddr) && h.RemoteAddr.Equal(other.RemoteAddr) && h.Priority == other.Priority && h.VRID == other.VRID }
go
func (h *HAConfig) Equal(other *HAConfig) bool { return h.Enabled == other.Enabled && h.LocalAddr.Equal(other.LocalAddr) && h.RemoteAddr.Equal(other.RemoteAddr) && h.Priority == other.Priority && h.VRID == other.VRID }
[ "func", "(", "h", "*", "HAConfig", ")", "Equal", "(", "other", "*", "HAConfig", ")", "bool", "{", "return", "h", ".", "Enabled", "==", "other", ".", "Enabled", "&&", "h", ".", "LocalAddr", ".", "Equal", "(", "other", ".", "LocalAddr", ")", "&&", "h", ".", "RemoteAddr", ".", "Equal", "(", "other", ".", "RemoteAddr", ")", "&&", "h", ".", "Priority", "==", "other", ".", "Priority", "&&", "h", ".", "VRID", "==", "other", ".", "VRID", "\n", "}" ]
// Equal reports whether this HAConfig is equal to the given HAConfig.
[ "Equal", "reports", "whether", "this", "HAConfig", "is", "equal", "to", "the", "given", "HAConfig", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L158-L164
train
google/seesaw
common/seesaw/util.go
String
func (h HAConfig) String() string { return fmt.Sprintf("Enabled: %v, LocalAddr: %v, RemoteAddr: %v, Priority: %d, VRID: %d", h.Enabled, h.LocalAddr, h.RemoteAddr, h.Priority, h.VRID) }
go
func (h HAConfig) String() string { return fmt.Sprintf("Enabled: %v, LocalAddr: %v, RemoteAddr: %v, Priority: %d, VRID: %d", h.Enabled, h.LocalAddr, h.RemoteAddr, h.Priority, h.VRID) }
[ "func", "(", "h", "HAConfig", ")", "String", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"Enabled: %v, LocalAddr: %v, RemoteAddr: %v, Priority: %d, VRID: %d\"", ",", "h", ".", "Enabled", ",", "h", ".", "LocalAddr", ",", "h", ".", "RemoteAddr", ",", "h", ".", "Priority", ",", "h", ".", "VRID", ")", "\n", "}" ]
// String returns the string representation of an HAConfig.
[ "String", "returns", "the", "string", "representation", "of", "an", "HAConfig", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L167-L170
train
google/seesaw
common/seesaw/util.go
String
func (h HAState) String() string { switch h { case HAUnknown: return "Unknown" case HABackup: return "Backup" case HADisabled: return "Disabled" case HAError: return "Error" case HAMaster: return "Master" case HAShutdown: return "Shutdown" } return "(invalid)" }
go
func (h HAState) String() string { switch h { case HAUnknown: return "Unknown" case HABackup: return "Backup" case HADisabled: return "Disabled" case HAError: return "Error" case HAMaster: return "Master" case HAShutdown: return "Shutdown" } return "(invalid)" }
[ "func", "(", "h", "HAState", ")", "String", "(", ")", "string", "{", "switch", "h", "{", "case", "HAUnknown", ":", "return", "\"Unknown\"", "\n", "case", "HABackup", ":", "return", "\"Backup\"", "\n", "case", "HADisabled", ":", "return", "\"Disabled\"", "\n", "case", "HAError", ":", "return", "\"Error\"", "\n", "case", "HAMaster", ":", "return", "\"Master\"", "\n", "case", "HAShutdown", ":", "return", "\"Shutdown\"", "\n", "}", "\n", "return", "\"(invalid)\"", "\n", "}" ]
// String returns the string representation of an HAState.
[ "String", "returns", "the", "string", "representation", "of", "an", "HAState", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L173-L189
train
google/seesaw
common/seesaw/util.go
Equal
func (v *VLAN) Equal(other *VLAN) bool { // Exclude backend and VIP counters from comparison. return v.ID == other.ID && v.Host.Equal(&other.Host) }
go
func (v *VLAN) Equal(other *VLAN) bool { // Exclude backend and VIP counters from comparison. return v.ID == other.ID && v.Host.Equal(&other.Host) }
[ "func", "(", "v", "*", "VLAN", ")", "Equal", "(", "other", "*", "VLAN", ")", "bool", "{", "return", "v", ".", "ID", "==", "other", ".", "ID", "&&", "v", ".", "Host", ".", "Equal", "(", "&", "other", ".", "Host", ")", "\n", "}" ]
// Equal reports whether this VLAN is equal to the given VLAN.
[ "Equal", "reports", "whether", "this", "VLAN", "is", "equal", "to", "the", "given", "VLAN", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L192-L195
train
google/seesaw
common/seesaw/util.go
String
func (v *VLAN) String() string { return fmt.Sprintf("{ID=%d, Host=%s, IPv4=%s, IPv6=%s}", v.ID, v.Hostname, v.IPv4Printable(), v.IPv6Printable()) }
go
func (v *VLAN) String() string { return fmt.Sprintf("{ID=%d, Host=%s, IPv4=%s, IPv6=%s}", v.ID, v.Hostname, v.IPv4Printable(), v.IPv6Printable()) }
[ "func", "(", "v", "*", "VLAN", ")", "String", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"{ID=%d, Host=%s, IPv4=%s, IPv6=%s}\"", ",", "v", ".", "ID", ",", "v", ".", "Hostname", ",", "v", ".", "IPv4Printable", "(", ")", ",", "v", ".", "IPv6Printable", "(", ")", ")", "\n", "}" ]
// String returns the string representation of a VLAN.
[ "String", "returns", "the", "string", "representation", "of", "a", "VLAN", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L203-L205
train
google/seesaw
common/seesaw/util.go
String
func (sk ServiceKey) String() string { return fmt.Sprintf("%s %s %d", sk.AF, sk.Proto, sk.Port) }
go
func (sk ServiceKey) String() string { return fmt.Sprintf("%s %s %d", sk.AF, sk.Proto, sk.Port) }
[ "func", "(", "sk", "ServiceKey", ")", "String", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"%s %s %d\"", ",", "sk", ".", "AF", ",", "sk", ".", "Proto", ",", "sk", ".", "Port", ")", "\n", "}" ]
// String returns the string representation of a ServiceKey.
[ "String", "returns", "the", "string", "representation", "of", "a", "ServiceKey", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L218-L220
train
google/seesaw
common/seesaw/util.go
IP
func (d *Destination) IP(af AF) net.IP { switch af { case IPv4: return d.Backend.IPv4Addr case IPv6: return d.Backend.IPv6Addr } return nil }
go
func (d *Destination) IP(af AF) net.IP { switch af { case IPv4: return d.Backend.IPv4Addr case IPv6: return d.Backend.IPv6Addr } return nil }
[ "func", "(", "d", "*", "Destination", ")", "IP", "(", "af", "AF", ")", "net", ".", "IP", "{", "switch", "af", "{", "case", "IPv4", ":", "return", "d", ".", "Backend", ".", "IPv4Addr", "\n", "case", "IPv6", ":", "return", "d", ".", "Backend", ".", "IPv6Addr", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// IP returns the destination IP address for a given address family.
[ "IP", "returns", "the", "destination", "IP", "address", "for", "a", "given", "address", "family", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L244-L252
train
google/seesaw
common/seesaw/util.go
copyIP
func copyIP(src net.IP) net.IP { return net.IP(copyBytes(src)) }
go
func copyIP(src net.IP) net.IP { return net.IP(copyBytes(src)) }
[ "func", "copyIP", "(", "src", "net", ".", "IP", ")", "net", ".", "IP", "{", "return", "net", ".", "IP", "(", "copyBytes", "(", "src", ")", ")", "\n", "}" ]
// copyIP creates a copy of an IP.
[ "copyIP", "creates", "a", "copy", "of", "an", "IP", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L262-L264
train
google/seesaw
common/seesaw/util.go
copyIPMask
func copyIPMask(src net.IPMask) net.IPMask { return net.IPMask(copyBytes(src)) }
go
func copyIPMask(src net.IPMask) net.IPMask { return net.IPMask(copyBytes(src)) }
[ "func", "copyIPMask", "(", "src", "net", ".", "IPMask", ")", "net", ".", "IPMask", "{", "return", "net", ".", "IPMask", "(", "copyBytes", "(", "src", ")", ")", "\n", "}" ]
// copyIPMask creates a copy of an IPMask.
[ "copyIPMask", "creates", "a", "copy", "of", "an", "IPMask", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L267-L269
train
google/seesaw
common/seesaw/util.go
copyBytes
func copyBytes(src []byte) []byte { if src == nil { return nil } dst := make([]byte, len(src)) copy(dst, src) return dst }
go
func copyBytes(src []byte) []byte { if src == nil { return nil } dst := make([]byte, len(src)) copy(dst, src) return dst }
[ "func", "copyBytes", "(", "src", "[", "]", "byte", ")", "[", "]", "byte", "{", "if", "src", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "dst", ":=", "make", "(", "[", "]", "byte", ",", "len", "(", "src", ")", ")", "\n", "copy", "(", "dst", ",", "src", ")", "\n", "return", "dst", "\n", "}" ]
// copyBytes creates a copy of a byte slice.
[ "copyBytes", "creates", "a", "copy", "of", "a", "byte", "slice", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L272-L279
train
google/seesaw
common/seesaw/util.go
IsAnycast
func IsAnycast(ip net.IP) bool { return netIPv4Anycast.Contains(ip) || netIPv6Anycast.Contains(ip) }
go
func IsAnycast(ip net.IP) bool { return netIPv4Anycast.Contains(ip) || netIPv6Anycast.Contains(ip) }
[ "func", "IsAnycast", "(", "ip", "net", ".", "IP", ")", "bool", "{", "return", "netIPv4Anycast", ".", "Contains", "(", "ip", ")", "||", "netIPv6Anycast", ".", "Contains", "(", "ip", ")", "\n", "}" ]
// IsAnycast reports whether an IP address is an anycast address.
[ "IsAnycast", "reports", "whether", "an", "IP", "address", "is", "an", "anycast", "address", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L282-L284
train
google/seesaw
common/seesaw/util.go
InSubnets
func InSubnets(ip net.IP, subnets map[string]*net.IPNet) bool { for _, subnet := range subnets { if subnet.Contains(ip) { return true } } return false }
go
func InSubnets(ip net.IP, subnets map[string]*net.IPNet) bool { for _, subnet := range subnets { if subnet.Contains(ip) { return true } } return false }
[ "func", "InSubnets", "(", "ip", "net", ".", "IP", ",", "subnets", "map", "[", "string", "]", "*", "net", ".", "IPNet", ")", "bool", "{", "for", "_", ",", "subnet", ":=", "range", "subnets", "{", "if", "subnet", ".", "Contains", "(", "ip", ")", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// InSubnets reports whether an IP address is in one of a map of subnets.
[ "InSubnets", "reports", "whether", "an", "IP", "address", "is", "in", "one", "of", "a", "map", "of", "subnets", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L287-L294
train
google/seesaw
engine/core.go
NewEngine
func NewEngine(cfg *config.EngineConfig) *Engine { if cfg == nil { defaultCfg := config.DefaultEngineConfig() cfg = &defaultCfg } // TODO(jsing): Validate node, peer and cluster IP configuration. engine := &Engine{ config: cfg, fwmAlloc: newMarkAllocator(fwmAllocBase, fwmAllocSize), ncc: ncclient.NewNCC(cfg.NCCSocket), overrides: make(map[string]seesaw.Override), overrideChan: make(chan seesaw.Override), vlans: make(map[uint16]*seesaw.VLAN), vservers: make(map[string]*vserver), shutdown: make(chan bool), shutdownARP: make(chan bool), shutdownIPC: make(chan bool), shutdownRPC: make(chan bool), vserverSnapshots: make(map[string]*seesaw.Vserver), vserverChan: make(chan *seesaw.Vserver, 1000), } engine.bgpManager = newBGPManager(engine, cfg.BGPUpdateInterval) engine.haManager = newHAManager(engine, cfg.HAStateTimeout) engine.hcManager = newHealthcheckManager(engine) engine.syncClient = newSyncClient(engine) engine.syncServer = newSyncServer(engine) return engine }
go
func NewEngine(cfg *config.EngineConfig) *Engine { if cfg == nil { defaultCfg := config.DefaultEngineConfig() cfg = &defaultCfg } // TODO(jsing): Validate node, peer and cluster IP configuration. engine := &Engine{ config: cfg, fwmAlloc: newMarkAllocator(fwmAllocBase, fwmAllocSize), ncc: ncclient.NewNCC(cfg.NCCSocket), overrides: make(map[string]seesaw.Override), overrideChan: make(chan seesaw.Override), vlans: make(map[uint16]*seesaw.VLAN), vservers: make(map[string]*vserver), shutdown: make(chan bool), shutdownARP: make(chan bool), shutdownIPC: make(chan bool), shutdownRPC: make(chan bool), vserverSnapshots: make(map[string]*seesaw.Vserver), vserverChan: make(chan *seesaw.Vserver, 1000), } engine.bgpManager = newBGPManager(engine, cfg.BGPUpdateInterval) engine.haManager = newHAManager(engine, cfg.HAStateTimeout) engine.hcManager = newHealthcheckManager(engine) engine.syncClient = newSyncClient(engine) engine.syncServer = newSyncServer(engine) return engine }
[ "func", "NewEngine", "(", "cfg", "*", "config", ".", "EngineConfig", ")", "*", "Engine", "{", "if", "cfg", "==", "nil", "{", "defaultCfg", ":=", "config", ".", "DefaultEngineConfig", "(", ")", "\n", "cfg", "=", "&", "defaultCfg", "\n", "}", "\n", "engine", ":=", "&", "Engine", "{", "config", ":", "cfg", ",", "fwmAlloc", ":", "newMarkAllocator", "(", "fwmAllocBase", ",", "fwmAllocSize", ")", ",", "ncc", ":", "ncclient", ".", "NewNCC", "(", "cfg", ".", "NCCSocket", ")", ",", "overrides", ":", "make", "(", "map", "[", "string", "]", "seesaw", ".", "Override", ")", ",", "overrideChan", ":", "make", "(", "chan", "seesaw", ".", "Override", ")", ",", "vlans", ":", "make", "(", "map", "[", "uint16", "]", "*", "seesaw", ".", "VLAN", ")", ",", "vservers", ":", "make", "(", "map", "[", "string", "]", "*", "vserver", ")", ",", "shutdown", ":", "make", "(", "chan", "bool", ")", ",", "shutdownARP", ":", "make", "(", "chan", "bool", ")", ",", "shutdownIPC", ":", "make", "(", "chan", "bool", ")", ",", "shutdownRPC", ":", "make", "(", "chan", "bool", ")", ",", "vserverSnapshots", ":", "make", "(", "map", "[", "string", "]", "*", "seesaw", ".", "Vserver", ")", ",", "vserverChan", ":", "make", "(", "chan", "*", "seesaw", ".", "Vserver", ",", "1000", ")", ",", "}", "\n", "engine", ".", "bgpManager", "=", "newBGPManager", "(", "engine", ",", "cfg", ".", "BGPUpdateInterval", ")", "\n", "engine", ".", "haManager", "=", "newHAManager", "(", "engine", ",", "cfg", ".", "HAStateTimeout", ")", "\n", "engine", ".", "hcManager", "=", "newHealthcheckManager", "(", "engine", ")", "\n", "engine", ".", "syncClient", "=", "newSyncClient", "(", "engine", ")", "\n", "engine", ".", "syncServer", "=", "newSyncServer", "(", "engine", ")", "\n", "return", "engine", "\n", "}" ]
// NewEngine returns an initialised Engine struct.
[ "NewEngine", "returns", "an", "initialised", "Engine", "struct", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L86-L117
train
google/seesaw
engine/core.go
Run
func (e *Engine) Run() { log.Infof("Seesaw Engine starting for %s", e.config.ClusterName) e.initNetwork() n, err := config.NewNotifier(e.config) if err != nil { log.Fatalf("config.NewNotifier() failed: %v", err) } e.notifier = n if e.config.AnycastEnabled { go e.bgpManager.run() } go e.hcManager.run() go e.syncClient.run() go e.syncServer.run() go e.syncRPC() go e.engineIPC() go e.gratuitousARP() e.manager() }
go
func (e *Engine) Run() { log.Infof("Seesaw Engine starting for %s", e.config.ClusterName) e.initNetwork() n, err := config.NewNotifier(e.config) if err != nil { log.Fatalf("config.NewNotifier() failed: %v", err) } e.notifier = n if e.config.AnycastEnabled { go e.bgpManager.run() } go e.hcManager.run() go e.syncClient.run() go e.syncServer.run() go e.syncRPC() go e.engineIPC() go e.gratuitousARP() e.manager() }
[ "func", "(", "e", "*", "Engine", ")", "Run", "(", ")", "{", "log", ".", "Infof", "(", "\"Seesaw Engine starting for %s\"", ",", "e", ".", "config", ".", "ClusterName", ")", "\n", "e", ".", "initNetwork", "(", ")", "\n", "n", ",", "err", ":=", "config", ".", "NewNotifier", "(", "e", ".", "config", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"config.NewNotifier() failed: %v\"", ",", "err", ")", "\n", "}", "\n", "e", ".", "notifier", "=", "n", "\n", "if", "e", ".", "config", ".", "AnycastEnabled", "{", "go", "e", ".", "bgpManager", ".", "run", "(", ")", "\n", "}", "\n", "go", "e", ".", "hcManager", ".", "run", "(", ")", "\n", "go", "e", ".", "syncClient", ".", "run", "(", ")", "\n", "go", "e", ".", "syncServer", ".", "run", "(", ")", "\n", "go", "e", ".", "syncRPC", "(", ")", "\n", "go", "e", ".", "engineIPC", "(", ")", "\n", "go", "e", ".", "gratuitousARP", "(", ")", "\n", "e", ".", "manager", "(", ")", "\n", "}" ]
// Run starts the Engine.
[ "Run", "starts", "the", "Engine", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L120-L144
train
google/seesaw
engine/core.go
haStatus
func (e *Engine) haStatus() seesaw.HAStatus { e.haManager.statusLock.RLock() defer e.haManager.statusLock.RUnlock() return e.haManager.status }
go
func (e *Engine) haStatus() seesaw.HAStatus { e.haManager.statusLock.RLock() defer e.haManager.statusLock.RUnlock() return e.haManager.status }
[ "func", "(", "e", "*", "Engine", ")", "haStatus", "(", ")", "seesaw", ".", "HAStatus", "{", "e", ".", "haManager", ".", "statusLock", ".", "RLock", "(", ")", "\n", "defer", "e", ".", "haManager", ".", "statusLock", ".", "RUnlock", "(", ")", "\n", "return", "e", ".", "haManager", ".", "status", "\n", "}" ]
// haStatus returns the current HA status from the engine.
[ "haStatus", "returns", "the", "current", "HA", "status", "from", "the", "engine", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L152-L156
train
google/seesaw
engine/core.go
setHAState
func (e *Engine) setHAState(state seesaw.HAState) { e.haManager.stateChan <- state }
go
func (e *Engine) setHAState(state seesaw.HAState) { e.haManager.stateChan <- state }
[ "func", "(", "e", "*", "Engine", ")", "setHAState", "(", "state", "seesaw", ".", "HAState", ")", "{", "e", ".", "haManager", ".", "stateChan", "<-", "state", "\n", "}" ]
// setHAState tells the engine what its current HAState should be.
[ "setHAState", "tells", "the", "engine", "what", "its", "current", "HAState", "should", "be", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L164-L166
train
google/seesaw
engine/core.go
setHAStatus
func (e *Engine) setHAStatus(status seesaw.HAStatus) { e.haManager.statusChan <- status }
go
func (e *Engine) setHAStatus(status seesaw.HAStatus) { e.haManager.statusChan <- status }
[ "func", "(", "e", "*", "Engine", ")", "setHAStatus", "(", "status", "seesaw", ".", "HAStatus", ")", "{", "e", ".", "haManager", ".", "statusChan", "<-", "status", "\n", "}" ]
// setHAStatus tells the engine what the current HA status is.
[ "setHAStatus", "tells", "the", "engine", "what", "the", "current", "HA", "status", "is", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L169-L171
train
google/seesaw
engine/core.go
haConfig
func (e *Engine) haConfig() (*seesaw.HAConfig, error) { n, err := e.thisNode() if err != nil { return nil, err } // TODO(jsing): This does not allow for IPv6-only operation. return &seesaw.HAConfig{ Enabled: n.State != seesaw.HADisabled, LocalAddr: e.config.Node.IPv4Addr, RemoteAddr: e.config.VRRPDestIP, Priority: n.Priority, VRID: e.config.VRID, }, nil }
go
func (e *Engine) haConfig() (*seesaw.HAConfig, error) { n, err := e.thisNode() if err != nil { return nil, err } // TODO(jsing): This does not allow for IPv6-only operation. return &seesaw.HAConfig{ Enabled: n.State != seesaw.HADisabled, LocalAddr: e.config.Node.IPv4Addr, RemoteAddr: e.config.VRRPDestIP, Priority: n.Priority, VRID: e.config.VRID, }, nil }
[ "func", "(", "e", "*", "Engine", ")", "haConfig", "(", ")", "(", "*", "seesaw", ".", "HAConfig", ",", "error", ")", "{", "n", ",", "err", ":=", "e", ".", "thisNode", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "seesaw", ".", "HAConfig", "{", "Enabled", ":", "n", ".", "State", "!=", "seesaw", ".", "HADisabled", ",", "LocalAddr", ":", "e", ".", "config", ".", "Node", ".", "IPv4Addr", ",", "RemoteAddr", ":", "e", ".", "config", ".", "VRRPDestIP", ",", "Priority", ":", "n", ".", "Priority", ",", "VRID", ":", "e", ".", "config", ".", "VRID", ",", "}", ",", "nil", "\n", "}" ]
// haConfig returns the HAConfig for an engine.
[ "haConfig", "returns", "the", "HAConfig", "for", "an", "engine", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L174-L187
train
google/seesaw
engine/core.go
thisNode
func (e *Engine) thisNode() (*seesaw.Node, error) { e.clusterLock.RLock() c := e.cluster e.clusterLock.RUnlock() if c == nil { return nil, fmt.Errorf("cluster configuration not loaded") } // TODO(jsing): This does not allow for IPv6-only operation. ip := e.config.Node.IPv4Addr for _, n := range c.Nodes { if ip.Equal(n.IPv4Addr) { return n, nil } } return nil, fmt.Errorf("node %v not configured", ip) }
go
func (e *Engine) thisNode() (*seesaw.Node, error) { e.clusterLock.RLock() c := e.cluster e.clusterLock.RUnlock() if c == nil { return nil, fmt.Errorf("cluster configuration not loaded") } // TODO(jsing): This does not allow for IPv6-only operation. ip := e.config.Node.IPv4Addr for _, n := range c.Nodes { if ip.Equal(n.IPv4Addr) { return n, nil } } return nil, fmt.Errorf("node %v not configured", ip) }
[ "func", "(", "e", "*", "Engine", ")", "thisNode", "(", ")", "(", "*", "seesaw", ".", "Node", ",", "error", ")", "{", "e", ".", "clusterLock", ".", "RLock", "(", ")", "\n", "c", ":=", "e", ".", "cluster", "\n", "e", ".", "clusterLock", ".", "RUnlock", "(", ")", "\n", "if", "c", "==", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"cluster configuration not loaded\"", ")", "\n", "}", "\n", "ip", ":=", "e", ".", "config", ".", "Node", ".", "IPv4Addr", "\n", "for", "_", ",", "n", ":=", "range", "c", ".", "Nodes", "{", "if", "ip", ".", "Equal", "(", "n", ".", "IPv4Addr", ")", "{", "return", "n", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"node %v not configured\"", ",", "ip", ")", "\n", "}" ]
// thisNode returns the Node for the machine on which this engine is running.
[ "thisNode", "returns", "the", "Node", "for", "the", "machine", "on", "which", "this", "engine", "is", "running", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L190-L206
train
google/seesaw
engine/core.go
engineIPC
func (e *Engine) engineIPC() { if err := server.RemoveUnixSocket(e.config.SocketPath); err != nil { log.Fatalf("Failed to remove socket: %v", err) } ln, err := net.Listen("unix", e.config.SocketPath) if err != nil { log.Fatalf("Listen failed: %v", err) } defer os.Remove(e.config.SocketPath) seesawIPC := rpc.NewServer() seesawIPC.Register(&SeesawEngine{e}) go server.RPCAccept(ln, seesawIPC) <-e.shutdownIPC ln.Close() e.shutdownIPC <- true }
go
func (e *Engine) engineIPC() { if err := server.RemoveUnixSocket(e.config.SocketPath); err != nil { log.Fatalf("Failed to remove socket: %v", err) } ln, err := net.Listen("unix", e.config.SocketPath) if err != nil { log.Fatalf("Listen failed: %v", err) } defer os.Remove(e.config.SocketPath) seesawIPC := rpc.NewServer() seesawIPC.Register(&SeesawEngine{e}) go server.RPCAccept(ln, seesawIPC) <-e.shutdownIPC ln.Close() e.shutdownIPC <- true }
[ "func", "(", "e", "*", "Engine", ")", "engineIPC", "(", ")", "{", "if", "err", ":=", "server", ".", "RemoveUnixSocket", "(", "e", ".", "config", ".", "SocketPath", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"Failed to remove socket: %v\"", ",", "err", ")", "\n", "}", "\n", "ln", ",", "err", ":=", "net", ".", "Listen", "(", "\"unix\"", ",", "e", ".", "config", ".", "SocketPath", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"Listen failed: %v\"", ",", "err", ")", "\n", "}", "\n", "defer", "os", ".", "Remove", "(", "e", ".", "config", ".", "SocketPath", ")", "\n", "seesawIPC", ":=", "rpc", ".", "NewServer", "(", ")", "\n", "seesawIPC", ".", "Register", "(", "&", "SeesawEngine", "{", "e", "}", ")", "\n", "go", "server", ".", "RPCAccept", "(", "ln", ",", "seesawIPC", ")", "\n", "<-", "e", ".", "shutdownIPC", "\n", "ln", ".", "Close", "(", ")", "\n", "e", ".", "shutdownIPC", "<-", "true", "\n", "}" ]
// engineIPC starts an RPC server to handle IPC via a Unix Domain socket.
[ "engineIPC", "starts", "an", "RPC", "server", "to", "handle", "IPC", "via", "a", "Unix", "Domain", "socket", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L209-L226
train
google/seesaw
engine/core.go
syncRPC
func (e *Engine) syncRPC() { // TODO(jsing): Make this default to IPv6, if configured. addr := &net.TCPAddr{ IP: e.config.Node.IPv4Addr, Port: e.config.SyncPort, } ln, err := net.ListenTCP("tcp", addr) if err != nil { log.Fatalf("Listen failed: %v", err) } go e.syncServer.serve(ln) <-e.shutdownRPC ln.Close() e.shutdownRPC <- true }
go
func (e *Engine) syncRPC() { // TODO(jsing): Make this default to IPv6, if configured. addr := &net.TCPAddr{ IP: e.config.Node.IPv4Addr, Port: e.config.SyncPort, } ln, err := net.ListenTCP("tcp", addr) if err != nil { log.Fatalf("Listen failed: %v", err) } go e.syncServer.serve(ln) <-e.shutdownRPC ln.Close() e.shutdownRPC <- true }
[ "func", "(", "e", "*", "Engine", ")", "syncRPC", "(", ")", "{", "addr", ":=", "&", "net", ".", "TCPAddr", "{", "IP", ":", "e", ".", "config", ".", "Node", ".", "IPv4Addr", ",", "Port", ":", "e", ".", "config", ".", "SyncPort", ",", "}", "\n", "ln", ",", "err", ":=", "net", ".", "ListenTCP", "(", "\"tcp\"", ",", "addr", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"Listen failed: %v\"", ",", "err", ")", "\n", "}", "\n", "go", "e", ".", "syncServer", ".", "serve", "(", "ln", ")", "\n", "<-", "e", ".", "shutdownRPC", "\n", "ln", ".", "Close", "(", ")", "\n", "e", ".", "shutdownRPC", "<-", "true", "\n", "}" ]
// syncRPC starts a server to handle synchronisation RPCs via a TCP socket.
[ "syncRPC", "starts", "a", "server", "to", "handle", "synchronisation", "RPCs", "via", "a", "TCP", "socket", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L229-L245
train
google/seesaw
engine/core.go
initNetwork
func (e *Engine) initNetwork() { if err := e.ncc.Dial(); err != nil { log.Fatalf("Failed to connect to NCC: %v", err) } defer e.ncc.Close() if e.config.AnycastEnabled { if err := e.ncc.BGPWithdrawAll(); err != nil { log.Fatalf("Failed to withdraw all BGP advertisements: %v", err) } } if err := e.ncc.IPVSFlush(); err != nil { log.Fatalf("Failed to flush IPVS table: %v", err) } lbCfg := &ncctypes.LBConfig{ ClusterVIP: e.config.ClusterVIP, DummyInterface: e.config.DummyInterface, NodeInterface: e.config.NodeInterface, Node: e.config.Node, RoutingTableID: e.config.RoutingTableID, VRID: e.config.VRID, } e.lbInterface = e.ncc.NewLBInterface(e.config.LBInterface, lbCfg) if err := e.lbInterface.Init(); err != nil { log.Fatalf("Failed to initialise LB interface: %v", err) } if e.config.AnycastEnabled { e.initAnycast() } }
go
func (e *Engine) initNetwork() { if err := e.ncc.Dial(); err != nil { log.Fatalf("Failed to connect to NCC: %v", err) } defer e.ncc.Close() if e.config.AnycastEnabled { if err := e.ncc.BGPWithdrawAll(); err != nil { log.Fatalf("Failed to withdraw all BGP advertisements: %v", err) } } if err := e.ncc.IPVSFlush(); err != nil { log.Fatalf("Failed to flush IPVS table: %v", err) } lbCfg := &ncctypes.LBConfig{ ClusterVIP: e.config.ClusterVIP, DummyInterface: e.config.DummyInterface, NodeInterface: e.config.NodeInterface, Node: e.config.Node, RoutingTableID: e.config.RoutingTableID, VRID: e.config.VRID, } e.lbInterface = e.ncc.NewLBInterface(e.config.LBInterface, lbCfg) if err := e.lbInterface.Init(); err != nil { log.Fatalf("Failed to initialise LB interface: %v", err) } if e.config.AnycastEnabled { e.initAnycast() } }
[ "func", "(", "e", "*", "Engine", ")", "initNetwork", "(", ")", "{", "if", "err", ":=", "e", ".", "ncc", ".", "Dial", "(", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"Failed to connect to NCC: %v\"", ",", "err", ")", "\n", "}", "\n", "defer", "e", ".", "ncc", ".", "Close", "(", ")", "\n", "if", "e", ".", "config", ".", "AnycastEnabled", "{", "if", "err", ":=", "e", ".", "ncc", ".", "BGPWithdrawAll", "(", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"Failed to withdraw all BGP advertisements: %v\"", ",", "err", ")", "\n", "}", "\n", "}", "\n", "if", "err", ":=", "e", ".", "ncc", ".", "IPVSFlush", "(", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"Failed to flush IPVS table: %v\"", ",", "err", ")", "\n", "}", "\n", "lbCfg", ":=", "&", "ncctypes", ".", "LBConfig", "{", "ClusterVIP", ":", "e", ".", "config", ".", "ClusterVIP", ",", "DummyInterface", ":", "e", ".", "config", ".", "DummyInterface", ",", "NodeInterface", ":", "e", ".", "config", ".", "NodeInterface", ",", "Node", ":", "e", ".", "config", ".", "Node", ",", "RoutingTableID", ":", "e", ".", "config", ".", "RoutingTableID", ",", "VRID", ":", "e", ".", "config", ".", "VRID", ",", "}", "\n", "e", ".", "lbInterface", "=", "e", ".", "ncc", ".", "NewLBInterface", "(", "e", ".", "config", ".", "LBInterface", ",", "lbCfg", ")", "\n", "if", "err", ":=", "e", ".", "lbInterface", ".", "Init", "(", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"Failed to initialise LB interface: %v\"", ",", "err", ")", "\n", "}", "\n", "if", "e", ".", "config", ".", "AnycastEnabled", "{", "e", ".", "initAnycast", "(", ")", "\n", "}", "\n", "}" ]
// initNetwork initialises the network configuration for load balancing.
[ "initNetwork", "initialises", "the", "network", "configuration", "for", "load", "balancing", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L248-L280
train
google/seesaw
engine/core.go
initAnycast
func (e *Engine) initAnycast() { if err := e.ncc.Dial(); err != nil { log.Fatalf("Failed to connect to NCC: %v", err) } defer e.ncc.Close() vips := make([]*seesaw.VIP, 0) if e.config.ClusterVIP.IPv4Addr != nil { for _, ip := range e.config.ServiceAnycastIPv4 { vips = append(vips, seesaw.NewVIP(ip, nil)) } } if e.config.ClusterVIP.IPv6Addr != nil { for _, ip := range e.config.ServiceAnycastIPv6 { vips = append(vips, seesaw.NewVIP(ip, nil)) } } for _, vip := range vips { if err := e.lbInterface.AddVIP(vip); err != nil { log.Fatalf("Failed to add VIP %v: %v", vip, err) } log.Infof("Advertising BGP route for %v", vip) if err := e.ncc.BGPAdvertiseVIP(vip.IP.IP()); err != nil { log.Fatalf("Failed to advertise VIP %v: %v", vip, err) } } }
go
func (e *Engine) initAnycast() { if err := e.ncc.Dial(); err != nil { log.Fatalf("Failed to connect to NCC: %v", err) } defer e.ncc.Close() vips := make([]*seesaw.VIP, 0) if e.config.ClusterVIP.IPv4Addr != nil { for _, ip := range e.config.ServiceAnycastIPv4 { vips = append(vips, seesaw.NewVIP(ip, nil)) } } if e.config.ClusterVIP.IPv6Addr != nil { for _, ip := range e.config.ServiceAnycastIPv6 { vips = append(vips, seesaw.NewVIP(ip, nil)) } } for _, vip := range vips { if err := e.lbInterface.AddVIP(vip); err != nil { log.Fatalf("Failed to add VIP %v: %v", vip, err) } log.Infof("Advertising BGP route for %v", vip) if err := e.ncc.BGPAdvertiseVIP(vip.IP.IP()); err != nil { log.Fatalf("Failed to advertise VIP %v: %v", vip, err) } } }
[ "func", "(", "e", "*", "Engine", ")", "initAnycast", "(", ")", "{", "if", "err", ":=", "e", ".", "ncc", ".", "Dial", "(", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"Failed to connect to NCC: %v\"", ",", "err", ")", "\n", "}", "\n", "defer", "e", ".", "ncc", ".", "Close", "(", ")", "\n", "vips", ":=", "make", "(", "[", "]", "*", "seesaw", ".", "VIP", ",", "0", ")", "\n", "if", "e", ".", "config", ".", "ClusterVIP", ".", "IPv4Addr", "!=", "nil", "{", "for", "_", ",", "ip", ":=", "range", "e", ".", "config", ".", "ServiceAnycastIPv4", "{", "vips", "=", "append", "(", "vips", ",", "seesaw", ".", "NewVIP", "(", "ip", ",", "nil", ")", ")", "\n", "}", "\n", "}", "\n", "if", "e", ".", "config", ".", "ClusterVIP", ".", "IPv6Addr", "!=", "nil", "{", "for", "_", ",", "ip", ":=", "range", "e", ".", "config", ".", "ServiceAnycastIPv6", "{", "vips", "=", "append", "(", "vips", ",", "seesaw", ".", "NewVIP", "(", "ip", ",", "nil", ")", ")", "\n", "}", "\n", "}", "\n", "for", "_", ",", "vip", ":=", "range", "vips", "{", "if", "err", ":=", "e", ".", "lbInterface", ".", "AddVIP", "(", "vip", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"Failed to add VIP %v: %v\"", ",", "vip", ",", "err", ")", "\n", "}", "\n", "log", ".", "Infof", "(", "\"Advertising BGP route for %v\"", ",", "vip", ")", "\n", "if", "err", ":=", "e", ".", "ncc", ".", "BGPAdvertiseVIP", "(", "vip", ".", "IP", ".", "IP", "(", ")", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"Failed to advertise VIP %v: %v\"", ",", "vip", ",", "err", ")", "\n", "}", "\n", "}", "\n", "}" ]
// initAnycast initialises the anycast configuration.
[ "initAnycast", "initialises", "the", "anycast", "configuration", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L283-L309
train
google/seesaw
engine/core.go
gratuitousARP
func (e *Engine) gratuitousARP() { arpTicker := time.NewTicker(e.config.GratuitousARPInterval) var announced bool for { select { case <-arpTicker.C: if e.haManager.state() != seesaw.HAMaster { if announced { log.Infof("Stopping gratuitous ARPs for %s", e.config.ClusterVIP.IPv4Addr) announced = false } continue } if !announced { log.Infof("Starting gratuitous ARPs for %s via %s every %s", e.config.ClusterVIP.IPv4Addr, e.config.LBInterface, e.config.GratuitousARPInterval) announced = true } if err := e.ncc.Dial(); err != nil { log.Fatalf("Failed to connect to NCC: %v", err) } defer e.ncc.Close() if err := e.ncc.ARPSendGratuitous(e.config.LBInterface, e.config.ClusterVIP.IPv4Addr); err != nil { log.Fatalf("Failed to send gratuitous ARP: %v", err) } case <-e.shutdownARP: e.shutdownARP <- true return } } }
go
func (e *Engine) gratuitousARP() { arpTicker := time.NewTicker(e.config.GratuitousARPInterval) var announced bool for { select { case <-arpTicker.C: if e.haManager.state() != seesaw.HAMaster { if announced { log.Infof("Stopping gratuitous ARPs for %s", e.config.ClusterVIP.IPv4Addr) announced = false } continue } if !announced { log.Infof("Starting gratuitous ARPs for %s via %s every %s", e.config.ClusterVIP.IPv4Addr, e.config.LBInterface, e.config.GratuitousARPInterval) announced = true } if err := e.ncc.Dial(); err != nil { log.Fatalf("Failed to connect to NCC: %v", err) } defer e.ncc.Close() if err := e.ncc.ARPSendGratuitous(e.config.LBInterface, e.config.ClusterVIP.IPv4Addr); err != nil { log.Fatalf("Failed to send gratuitous ARP: %v", err) } case <-e.shutdownARP: e.shutdownARP <- true return } } }
[ "func", "(", "e", "*", "Engine", ")", "gratuitousARP", "(", ")", "{", "arpTicker", ":=", "time", ".", "NewTicker", "(", "e", ".", "config", ".", "GratuitousARPInterval", ")", "\n", "var", "announced", "bool", "\n", "for", "{", "select", "{", "case", "<-", "arpTicker", ".", "C", ":", "if", "e", ".", "haManager", ".", "state", "(", ")", "!=", "seesaw", ".", "HAMaster", "{", "if", "announced", "{", "log", ".", "Infof", "(", "\"Stopping gratuitous ARPs for %s\"", ",", "e", ".", "config", ".", "ClusterVIP", ".", "IPv4Addr", ")", "\n", "announced", "=", "false", "\n", "}", "\n", "continue", "\n", "}", "\n", "if", "!", "announced", "{", "log", ".", "Infof", "(", "\"Starting gratuitous ARPs for %s via %s every %s\"", ",", "e", ".", "config", ".", "ClusterVIP", ".", "IPv4Addr", ",", "e", ".", "config", ".", "LBInterface", ",", "e", ".", "config", ".", "GratuitousARPInterval", ")", "\n", "announced", "=", "true", "\n", "}", "\n", "if", "err", ":=", "e", ".", "ncc", ".", "Dial", "(", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"Failed to connect to NCC: %v\"", ",", "err", ")", "\n", "}", "\n", "defer", "e", ".", "ncc", ".", "Close", "(", ")", "\n", "if", "err", ":=", "e", ".", "ncc", ".", "ARPSendGratuitous", "(", "e", ".", "config", ".", "LBInterface", ",", "e", ".", "config", ".", "ClusterVIP", ".", "IPv4Addr", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"Failed to send gratuitous ARP: %v\"", ",", "err", ")", "\n", "}", "\n", "case", "<-", "e", ".", "shutdownARP", ":", "e", ".", "shutdownARP", "<-", "true", "\n", "return", "\n", "}", "\n", "}", "\n", "}" ]
// gratuitousARP sends gratuitous ARP messages at regular intervals, if this // node is the HA master.
[ "gratuitousARP", "sends", "gratuitous", "ARP", "messages", "at", "regular", "intervals", "if", "this", "node", "is", "the", "HA", "master", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L313-L344
train
google/seesaw
engine/core.go
updateVservers
func (e *Engine) updateVservers() { e.clusterLock.RLock() cluster := e.cluster e.clusterLock.RUnlock() // Delete vservers that no longer exist in the new configuration. for name, vserver := range e.vservers { if cluster.Vservers[name] == nil { log.Infof("Stopping unconfigured vserver %s", name) vserver.stop() <-vserver.stopped delete(e.vservers, name) e.vserverLock.Lock() delete(e.vserverSnapshots, name) e.vserverLock.Unlock() } } // Spawn new vservers and provide current configurations. for _, config := range cluster.Vservers { if e.vservers[config.Name] == nil { vserver := newVserver(e) go vserver.run() e.vservers[config.Name] = vserver } } for _, override := range e.overrides { e.distributeOverride(override) } for _, config := range cluster.Vservers { e.vservers[config.Name].updateConfig(config) } }
go
func (e *Engine) updateVservers() { e.clusterLock.RLock() cluster := e.cluster e.clusterLock.RUnlock() // Delete vservers that no longer exist in the new configuration. for name, vserver := range e.vservers { if cluster.Vservers[name] == nil { log.Infof("Stopping unconfigured vserver %s", name) vserver.stop() <-vserver.stopped delete(e.vservers, name) e.vserverLock.Lock() delete(e.vserverSnapshots, name) e.vserverLock.Unlock() } } // Spawn new vservers and provide current configurations. for _, config := range cluster.Vservers { if e.vservers[config.Name] == nil { vserver := newVserver(e) go vserver.run() e.vservers[config.Name] = vserver } } for _, override := range e.overrides { e.distributeOverride(override) } for _, config := range cluster.Vservers { e.vservers[config.Name].updateConfig(config) } }
[ "func", "(", "e", "*", "Engine", ")", "updateVservers", "(", ")", "{", "e", ".", "clusterLock", ".", "RLock", "(", ")", "\n", "cluster", ":=", "e", ".", "cluster", "\n", "e", ".", "clusterLock", ".", "RUnlock", "(", ")", "\n", "for", "name", ",", "vserver", ":=", "range", "e", ".", "vservers", "{", "if", "cluster", ".", "Vservers", "[", "name", "]", "==", "nil", "{", "log", ".", "Infof", "(", "\"Stopping unconfigured vserver %s\"", ",", "name", ")", "\n", "vserver", ".", "stop", "(", ")", "\n", "<-", "vserver", ".", "stopped", "\n", "delete", "(", "e", ".", "vservers", ",", "name", ")", "\n", "e", ".", "vserverLock", ".", "Lock", "(", ")", "\n", "delete", "(", "e", ".", "vserverSnapshots", ",", "name", ")", "\n", "e", ".", "vserverLock", ".", "Unlock", "(", ")", "\n", "}", "\n", "}", "\n", "for", "_", ",", "config", ":=", "range", "cluster", ".", "Vservers", "{", "if", "e", ".", "vservers", "[", "config", ".", "Name", "]", "==", "nil", "{", "vserver", ":=", "newVserver", "(", "e", ")", "\n", "go", "vserver", ".", "run", "(", ")", "\n", "e", ".", "vservers", "[", "config", ".", "Name", "]", "=", "vserver", "\n", "}", "\n", "}", "\n", "for", "_", ",", "override", ":=", "range", "e", ".", "overrides", "{", "e", ".", "distributeOverride", "(", "override", ")", "\n", "}", "\n", "for", "_", ",", "config", ":=", "range", "cluster", ".", "Vservers", "{", "e", ".", "vservers", "[", "config", ".", "Name", "]", ".", "updateConfig", "(", "config", ")", "\n", "}", "\n", "}" ]
// updateVservers processes a list of vserver configurations then stops // deleted vservers, spawns new vservers and updates the existing vservers.
[ "updateVservers", "processes", "a", "list", "of", "vserver", "configurations", "then", "stops", "deleted", "vservers", "spawns", "new", "vservers", "and", "updates", "the", "existing", "vservers", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L448-L480
train
google/seesaw
engine/core.go
shutdownVservers
func (e *Engine) shutdownVservers() { for _, v := range e.vservers { v.stop() } for name, v := range e.vservers { <-v.stopped delete(e.vservers, name) } e.vserverLock.Lock() e.vserverSnapshots = make(map[string]*seesaw.Vserver) e.vserverLock.Unlock() }
go
func (e *Engine) shutdownVservers() { for _, v := range e.vservers { v.stop() } for name, v := range e.vservers { <-v.stopped delete(e.vservers, name) } e.vserverLock.Lock() e.vserverSnapshots = make(map[string]*seesaw.Vserver) e.vserverLock.Unlock() }
[ "func", "(", "e", "*", "Engine", ")", "shutdownVservers", "(", ")", "{", "for", "_", ",", "v", ":=", "range", "e", ".", "vservers", "{", "v", ".", "stop", "(", ")", "\n", "}", "\n", "for", "name", ",", "v", ":=", "range", "e", ".", "vservers", "{", "<-", "v", ".", "stopped", "\n", "delete", "(", "e", ".", "vservers", ",", "name", ")", "\n", "}", "\n", "e", ".", "vserverLock", ".", "Lock", "(", ")", "\n", "e", ".", "vserverSnapshots", "=", "make", "(", "map", "[", "string", "]", "*", "seesaw", ".", "Vserver", ")", "\n", "e", ".", "vserverLock", ".", "Unlock", "(", ")", "\n", "}" ]
// shutdownVservers shuts down all running vservers.
[ "shutdownVservers", "shuts", "down", "all", "running", "vservers", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L483-L494
train
google/seesaw
engine/core.go
updateVLANs
func (e *Engine) updateVLANs() { e.clusterLock.RLock() cluster := e.cluster e.clusterLock.RUnlock() add := make([]*seesaw.VLAN, 0) remove := make([]*seesaw.VLAN, 0) e.vlanLock.Lock() defer e.vlanLock.Unlock() for key, vlan := range e.vlans { if cluster.VLANs[key] == nil { remove = append(remove, vlan) } else if !vlan.Equal(cluster.VLANs[key]) { // TODO(angusc): This will break any VIPs that are currently configured // on the VLAN interface. Fix! remove = append(remove, vlan) add = append(add, cluster.VLANs[key]) } } for key, vlan := range cluster.VLANs { if e.vlans[key] == nil { add = append(add, vlan) } } if err := e.ncc.Dial(); err != nil { log.Fatalf("Failed to connect to NCC: %v", err) } defer e.ncc.Close() for _, vlan := range remove { log.Infof("Removing VLAN interface %v", vlan) if err := e.lbInterface.DeleteVLAN(vlan); err != nil { log.Fatalf("Failed to remove VLAN interface %v: %v", vlan, err) } } for _, vlan := range add { log.Infof("Adding VLAN interface %v", vlan) if err := e.lbInterface.AddVLAN(vlan); err != nil { log.Fatalf("Failed to add VLAN interface %v: %v", vlan, err) } } e.vlans = cluster.VLANs }
go
func (e *Engine) updateVLANs() { e.clusterLock.RLock() cluster := e.cluster e.clusterLock.RUnlock() add := make([]*seesaw.VLAN, 0) remove := make([]*seesaw.VLAN, 0) e.vlanLock.Lock() defer e.vlanLock.Unlock() for key, vlan := range e.vlans { if cluster.VLANs[key] == nil { remove = append(remove, vlan) } else if !vlan.Equal(cluster.VLANs[key]) { // TODO(angusc): This will break any VIPs that are currently configured // on the VLAN interface. Fix! remove = append(remove, vlan) add = append(add, cluster.VLANs[key]) } } for key, vlan := range cluster.VLANs { if e.vlans[key] == nil { add = append(add, vlan) } } if err := e.ncc.Dial(); err != nil { log.Fatalf("Failed to connect to NCC: %v", err) } defer e.ncc.Close() for _, vlan := range remove { log.Infof("Removing VLAN interface %v", vlan) if err := e.lbInterface.DeleteVLAN(vlan); err != nil { log.Fatalf("Failed to remove VLAN interface %v: %v", vlan, err) } } for _, vlan := range add { log.Infof("Adding VLAN interface %v", vlan) if err := e.lbInterface.AddVLAN(vlan); err != nil { log.Fatalf("Failed to add VLAN interface %v: %v", vlan, err) } } e.vlans = cluster.VLANs }
[ "func", "(", "e", "*", "Engine", ")", "updateVLANs", "(", ")", "{", "e", ".", "clusterLock", ".", "RLock", "(", ")", "\n", "cluster", ":=", "e", ".", "cluster", "\n", "e", ".", "clusterLock", ".", "RUnlock", "(", ")", "\n", "add", ":=", "make", "(", "[", "]", "*", "seesaw", ".", "VLAN", ",", "0", ")", "\n", "remove", ":=", "make", "(", "[", "]", "*", "seesaw", ".", "VLAN", ",", "0", ")", "\n", "e", ".", "vlanLock", ".", "Lock", "(", ")", "\n", "defer", "e", ".", "vlanLock", ".", "Unlock", "(", ")", "\n", "for", "key", ",", "vlan", ":=", "range", "e", ".", "vlans", "{", "if", "cluster", ".", "VLANs", "[", "key", "]", "==", "nil", "{", "remove", "=", "append", "(", "remove", ",", "vlan", ")", "\n", "}", "else", "if", "!", "vlan", ".", "Equal", "(", "cluster", ".", "VLANs", "[", "key", "]", ")", "{", "remove", "=", "append", "(", "remove", ",", "vlan", ")", "\n", "add", "=", "append", "(", "add", ",", "cluster", ".", "VLANs", "[", "key", "]", ")", "\n", "}", "\n", "}", "\n", "for", "key", ",", "vlan", ":=", "range", "cluster", ".", "VLANs", "{", "if", "e", ".", "vlans", "[", "key", "]", "==", "nil", "{", "add", "=", "append", "(", "add", ",", "vlan", ")", "\n", "}", "\n", "}", "\n", "if", "err", ":=", "e", ".", "ncc", ".", "Dial", "(", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"Failed to connect to NCC: %v\"", ",", "err", ")", "\n", "}", "\n", "defer", "e", ".", "ncc", ".", "Close", "(", ")", "\n", "for", "_", ",", "vlan", ":=", "range", "remove", "{", "log", ".", "Infof", "(", "\"Removing VLAN interface %v\"", ",", "vlan", ")", "\n", "if", "err", ":=", "e", ".", "lbInterface", ".", "DeleteVLAN", "(", "vlan", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"Failed to remove VLAN interface %v: %v\"", ",", "vlan", ",", "err", ")", "\n", "}", "\n", "}", "\n", "for", "_", ",", "vlan", ":=", "range", "add", "{", "log", ".", "Infof", "(", "\"Adding VLAN interface %v\"", ",", "vlan", ")", "\n", "if", "err", ":=", "e", ".", "lbInterface", ".", "AddVLAN", "(", "vlan", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"Failed to add VLAN interface %v: %v\"", ",", "vlan", ",", "err", ")", "\n", "}", "\n", "}", "\n", "e", ".", "vlans", "=", "cluster", ".", "VLANs", "\n", "}" ]
// updateVLANs creates and destroys VLAN interfaces for the load balancer per // the cluster configuration.
[ "updateVLANs", "creates", "and", "destroys", "VLAN", "interfaces", "for", "the", "load", "balancer", "per", "the", "cluster", "configuration", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L498-L544
train
google/seesaw
engine/core.go
deleteVLANs
func (e *Engine) deleteVLANs() { if err := e.ncc.Dial(); err != nil { log.Fatalf("Failed to connect to NCC: %v", err) } defer e.ncc.Close() e.vlanLock.Lock() defer e.vlanLock.Unlock() for k, v := range e.vlans { if err := e.lbInterface.DeleteVLAN(v); err != nil { log.Fatalf("Failed to remove VLAN interface %v: %v", v, err) } delete(e.vlans, k) } }
go
func (e *Engine) deleteVLANs() { if err := e.ncc.Dial(); err != nil { log.Fatalf("Failed to connect to NCC: %v", err) } defer e.ncc.Close() e.vlanLock.Lock() defer e.vlanLock.Unlock() for k, v := range e.vlans { if err := e.lbInterface.DeleteVLAN(v); err != nil { log.Fatalf("Failed to remove VLAN interface %v: %v", v, err) } delete(e.vlans, k) } }
[ "func", "(", "e", "*", "Engine", ")", "deleteVLANs", "(", ")", "{", "if", "err", ":=", "e", ".", "ncc", ".", "Dial", "(", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"Failed to connect to NCC: %v\"", ",", "err", ")", "\n", "}", "\n", "defer", "e", ".", "ncc", ".", "Close", "(", ")", "\n", "e", ".", "vlanLock", ".", "Lock", "(", ")", "\n", "defer", "e", ".", "vlanLock", ".", "Unlock", "(", ")", "\n", "for", "k", ",", "v", ":=", "range", "e", ".", "vlans", "{", "if", "err", ":=", "e", ".", "lbInterface", ".", "DeleteVLAN", "(", "v", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"Failed to remove VLAN interface %v: %v\"", ",", "v", ",", "err", ")", "\n", "}", "\n", "delete", "(", "e", ".", "vlans", ",", "k", ")", "\n", "}", "\n", "}" ]
// deleteVLANs removes all the VLAN interfaces that have been created by this // engine.
[ "deleteVLANs", "removes", "all", "the", "VLAN", "interfaces", "that", "have", "been", "created", "by", "this", "engine", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L548-L563
train
google/seesaw
engine/core.go
handleOverride
func (e *Engine) handleOverride(o seesaw.Override) { e.overrides[o.Target()] = o e.distributeOverride(o) if o.State() == seesaw.OverrideDefault { delete(e.overrides, o.Target()) } }
go
func (e *Engine) handleOverride(o seesaw.Override) { e.overrides[o.Target()] = o e.distributeOverride(o) if o.State() == seesaw.OverrideDefault { delete(e.overrides, o.Target()) } }
[ "func", "(", "e", "*", "Engine", ")", "handleOverride", "(", "o", "seesaw", ".", "Override", ")", "{", "e", ".", "overrides", "[", "o", ".", "Target", "(", ")", "]", "=", "o", "\n", "e", ".", "distributeOverride", "(", "o", ")", "\n", "if", "o", ".", "State", "(", ")", "==", "seesaw", ".", "OverrideDefault", "{", "delete", "(", "e", ".", "overrides", ",", "o", ".", "Target", "(", ")", ")", "\n", "}", "\n", "}" ]
// handleOverride handles an incoming Override.
[ "handleOverride", "handles", "an", "incoming", "Override", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L566-L572
train
google/seesaw
engine/core.go
distributeOverride
func (e *Engine) distributeOverride(o seesaw.Override) { // Send VserverOverrides and DestinationOverrides to the appropriate vserver. // Send BackendOverrides to all vservers. switch override := o.(type) { case *seesaw.VserverOverride: if vserver, ok := e.vservers[override.VserverName]; ok { vserver.queueOverride(o) } case *seesaw.DestinationOverride: if vserver, ok := e.vservers[override.VserverName]; ok { vserver.queueOverride(o) } case *seesaw.BackendOverride: for _, vserver := range e.vservers { vserver.queueOverride(o) } } }
go
func (e *Engine) distributeOverride(o seesaw.Override) { // Send VserverOverrides and DestinationOverrides to the appropriate vserver. // Send BackendOverrides to all vservers. switch override := o.(type) { case *seesaw.VserverOverride: if vserver, ok := e.vservers[override.VserverName]; ok { vserver.queueOverride(o) } case *seesaw.DestinationOverride: if vserver, ok := e.vservers[override.VserverName]; ok { vserver.queueOverride(o) } case *seesaw.BackendOverride: for _, vserver := range e.vservers { vserver.queueOverride(o) } } }
[ "func", "(", "e", "*", "Engine", ")", "distributeOverride", "(", "o", "seesaw", ".", "Override", ")", "{", "switch", "override", ":=", "o", ".", "(", "type", ")", "{", "case", "*", "seesaw", ".", "VserverOverride", ":", "if", "vserver", ",", "ok", ":=", "e", ".", "vservers", "[", "override", ".", "VserverName", "]", ";", "ok", "{", "vserver", ".", "queueOverride", "(", "o", ")", "\n", "}", "\n", "case", "*", "seesaw", ".", "DestinationOverride", ":", "if", "vserver", ",", "ok", ":=", "e", ".", "vservers", "[", "override", ".", "VserverName", "]", ";", "ok", "{", "vserver", ".", "queueOverride", "(", "o", ")", "\n", "}", "\n", "case", "*", "seesaw", ".", "BackendOverride", ":", "for", "_", ",", "vserver", ":=", "range", "e", ".", "vservers", "{", "vserver", ".", "queueOverride", "(", "o", ")", "\n", "}", "\n", "}", "\n", "}" ]
// distributeOverride distributes an Override to the appropriate vservers.
[ "distributeOverride", "distributes", "an", "Override", "to", "the", "appropriate", "vservers", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L575-L592
train
google/seesaw
engine/core.go
becomeMaster
func (e *Engine) becomeMaster() { if err := e.ncc.Dial(); err != nil { log.Fatalf("Failed to connect to NCC: %v", err) } defer e.ncc.Close() e.syncClient.disable() e.hcManager.enable() e.notifier.SetSource(config.SourceServer) if err := e.lbInterface.Up(); err != nil { log.Fatalf("Failed to bring LB interface up: %v", err) } }
go
func (e *Engine) becomeMaster() { if err := e.ncc.Dial(); err != nil { log.Fatalf("Failed to connect to NCC: %v", err) } defer e.ncc.Close() e.syncClient.disable() e.hcManager.enable() e.notifier.SetSource(config.SourceServer) if err := e.lbInterface.Up(); err != nil { log.Fatalf("Failed to bring LB interface up: %v", err) } }
[ "func", "(", "e", "*", "Engine", ")", "becomeMaster", "(", ")", "{", "if", "err", ":=", "e", ".", "ncc", ".", "Dial", "(", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"Failed to connect to NCC: %v\"", ",", "err", ")", "\n", "}", "\n", "defer", "e", ".", "ncc", ".", "Close", "(", ")", "\n", "e", ".", "syncClient", ".", "disable", "(", ")", "\n", "e", ".", "hcManager", ".", "enable", "(", ")", "\n", "e", ".", "notifier", ".", "SetSource", "(", "config", ".", "SourceServer", ")", "\n", "if", "err", ":=", "e", ".", "lbInterface", ".", "Up", "(", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"Failed to bring LB interface up: %v\"", ",", "err", ")", "\n", "}", "\n", "}" ]
// becomeMaster performs the necessary actions for the Seesaw Engine to // become the master node.
[ "becomeMaster", "performs", "the", "necessary", "actions", "for", "the", "Seesaw", "Engine", "to", "become", "the", "master", "node", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L596-L609
train
google/seesaw
engine/core.go
becomeBackup
func (e *Engine) becomeBackup() { if err := e.ncc.Dial(); err != nil { log.Fatalf("Failed to connect to NCC: %v", err) } defer e.ncc.Close() e.syncClient.enable() e.hcManager.disable() e.notifier.SetSource(config.SourcePeer) if err := e.lbInterface.Down(); err != nil { log.Fatalf("Failed to bring LB interface down: %v", err) } // TODO(jsing): Once peer synchronisation is implemented, make this // a time-based expiration that commences once communication with the // peer is lost. e.hcManager.expire() }
go
func (e *Engine) becomeBackup() { if err := e.ncc.Dial(); err != nil { log.Fatalf("Failed to connect to NCC: %v", err) } defer e.ncc.Close() e.syncClient.enable() e.hcManager.disable() e.notifier.SetSource(config.SourcePeer) if err := e.lbInterface.Down(); err != nil { log.Fatalf("Failed to bring LB interface down: %v", err) } // TODO(jsing): Once peer synchronisation is implemented, make this // a time-based expiration that commences once communication with the // peer is lost. e.hcManager.expire() }
[ "func", "(", "e", "*", "Engine", ")", "becomeBackup", "(", ")", "{", "if", "err", ":=", "e", ".", "ncc", ".", "Dial", "(", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"Failed to connect to NCC: %v\"", ",", "err", ")", "\n", "}", "\n", "defer", "e", ".", "ncc", ".", "Close", "(", ")", "\n", "e", ".", "syncClient", ".", "enable", "(", ")", "\n", "e", ".", "hcManager", ".", "disable", "(", ")", "\n", "e", ".", "notifier", ".", "SetSource", "(", "config", ".", "SourcePeer", ")", "\n", "if", "err", ":=", "e", ".", "lbInterface", ".", "Down", "(", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"Failed to bring LB interface down: %v\"", ",", "err", ")", "\n", "}", "\n", "e", ".", "hcManager", ".", "expire", "(", ")", "\n", "}" ]
// becomeBackup performs the neccesary actions for the Seesaw Engine to // stop being the master node and become the backup node.
[ "becomeBackup", "performs", "the", "neccesary", "actions", "for", "the", "Seesaw", "Engine", "to", "stop", "being", "the", "master", "node", "and", "become", "the", "backup", "node", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L613-L631
train
google/seesaw
engine/core.go
newMarkAllocator
func newMarkAllocator(base, size int) *markAllocator { ma := &markAllocator{ marks: make([]uint32, 0, size), } for i := 0; i < size; i++ { ma.put(uint32(base + i)) } return ma }
go
func newMarkAllocator(base, size int) *markAllocator { ma := &markAllocator{ marks: make([]uint32, 0, size), } for i := 0; i < size; i++ { ma.put(uint32(base + i)) } return ma }
[ "func", "newMarkAllocator", "(", "base", ",", "size", "int", ")", "*", "markAllocator", "{", "ma", ":=", "&", "markAllocator", "{", "marks", ":", "make", "(", "[", "]", "uint32", ",", "0", ",", "size", ")", ",", "}", "\n", "for", "i", ":=", "0", ";", "i", "<", "size", ";", "i", "++", "{", "ma", ".", "put", "(", "uint32", "(", "base", "+", "i", ")", ")", "\n", "}", "\n", "return", "ma", "\n", "}" ]
// newMarkAllocator returns a mark allocator initialised with the specified // base and size.
[ "newMarkAllocator", "returns", "a", "mark", "allocator", "initialised", "with", "the", "specified", "base", "and", "size", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L641-L649
train
google/seesaw
engine/core.go
get
func (ma *markAllocator) get() (uint32, error) { ma.lock.Lock() defer ma.lock.Unlock() if len(ma.marks) == 0 { return 0, errors.New("allocator exhausted") } mark := ma.marks[0] ma.marks = ma.marks[1:] return mark, nil }
go
func (ma *markAllocator) get() (uint32, error) { ma.lock.Lock() defer ma.lock.Unlock() if len(ma.marks) == 0 { return 0, errors.New("allocator exhausted") } mark := ma.marks[0] ma.marks = ma.marks[1:] return mark, nil }
[ "func", "(", "ma", "*", "markAllocator", ")", "get", "(", ")", "(", "uint32", ",", "error", ")", "{", "ma", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "ma", ".", "lock", ".", "Unlock", "(", ")", "\n", "if", "len", "(", "ma", ".", "marks", ")", "==", "0", "{", "return", "0", ",", "errors", ".", "New", "(", "\"allocator exhausted\"", ")", "\n", "}", "\n", "mark", ":=", "ma", ".", "marks", "[", "0", "]", "\n", "ma", ".", "marks", "=", "ma", ".", "marks", "[", "1", ":", "]", "\n", "return", "mark", ",", "nil", "\n", "}" ]
// get returns the next available mark from the mark allocator.
[ "get", "returns", "the", "next", "available", "mark", "from", "the", "mark", "allocator", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L652-L661
train
google/seesaw
engine/core.go
put
func (ma *markAllocator) put(mark uint32) { ma.lock.Lock() defer ma.lock.Unlock() ma.marks = append(ma.marks, mark) }
go
func (ma *markAllocator) put(mark uint32) { ma.lock.Lock() defer ma.lock.Unlock() ma.marks = append(ma.marks, mark) }
[ "func", "(", "ma", "*", "markAllocator", ")", "put", "(", "mark", "uint32", ")", "{", "ma", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "ma", ".", "lock", ".", "Unlock", "(", ")", "\n", "ma", ".", "marks", "=", "append", "(", "ma", ".", "marks", ",", "mark", ")", "\n", "}" ]
// put returns the specified mark to the mark allocator.
[ "put", "returns", "the", "specified", "mark", "to", "the", "mark", "allocator", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L664-L668
train
google/seesaw
ecu/auth.go
authenticate
func (e *ECU) authenticate(ctx *ipc.Context) (*ipc.Context, error) { return nil, errors.New("unimplemented") }
go
func (e *ECU) authenticate(ctx *ipc.Context) (*ipc.Context, error) { return nil, errors.New("unimplemented") }
[ "func", "(", "e", "*", "ECU", ")", "authenticate", "(", "ctx", "*", "ipc", ".", "Context", ")", "(", "*", "ipc", ".", "Context", ",", "error", ")", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"unimplemented\"", ")", "\n", "}" ]
// authenticate attempts to validate the given authentication token.
[ "authenticate", "attempts", "to", "validate", "the", "given", "authentication", "token", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ecu/auth.go#L36-L38
train
google/seesaw
ecu/auth.go
authConnect
func (e *ECU) authConnect(ctx *ipc.Context) (*conn.Seesaw, error) { if ctx == nil { return nil, errors.New("context is nil") } authCtx, err := e.authenticate(ctx) if err != nil { return nil, fmt.Errorf("authentication failed: %v", err) } seesawConn, err := conn.NewSeesawIPC(authCtx) if err != nil { return nil, fmt.Errorf("failed to connect to engine: %v", err) } if err := seesawConn.Dial(e.cfg.EngineSocket); err != nil { return nil, fmt.Errorf("failed to connect to engine: %v", err) } return seesawConn, nil }
go
func (e *ECU) authConnect(ctx *ipc.Context) (*conn.Seesaw, error) { if ctx == nil { return nil, errors.New("context is nil") } authCtx, err := e.authenticate(ctx) if err != nil { return nil, fmt.Errorf("authentication failed: %v", err) } seesawConn, err := conn.NewSeesawIPC(authCtx) if err != nil { return nil, fmt.Errorf("failed to connect to engine: %v", err) } if err := seesawConn.Dial(e.cfg.EngineSocket); err != nil { return nil, fmt.Errorf("failed to connect to engine: %v", err) } return seesawConn, nil }
[ "func", "(", "e", "*", "ECU", ")", "authConnect", "(", "ctx", "*", "ipc", ".", "Context", ")", "(", "*", "conn", ".", "Seesaw", ",", "error", ")", "{", "if", "ctx", "==", "nil", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"context is nil\"", ")", "\n", "}", "\n", "authCtx", ",", "err", ":=", "e", ".", "authenticate", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"authentication failed: %v\"", ",", "err", ")", "\n", "}", "\n", "seesawConn", ",", "err", ":=", "conn", ".", "NewSeesawIPC", "(", "authCtx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"failed to connect to engine: %v\"", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "seesawConn", ".", "Dial", "(", "e", ".", "cfg", ".", "EngineSocket", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"failed to connect to engine: %v\"", ",", "err", ")", "\n", "}", "\n", "return", "seesawConn", ",", "nil", "\n", "}" ]
// authConnect attempts to authenticate the user using the given context. If // authentication succeeds an authenticated IPC connection to the Seesaw // Engine is returned.
[ "authConnect", "attempts", "to", "authenticate", "the", "user", "using", "the", "given", "context", ".", "If", "authentication", "succeeds", "an", "authenticated", "IPC", "connection", "to", "the", "Seesaw", "Engine", "is", "returned", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ecu/auth.go#L43-L61
train
google/seesaw
binaries/seesaw_cli/main.go
commandChain
func commandChain(chain []*cli.Command, args []string) string { s := make([]string, 0) for _, c := range chain { s = append(s, c.Command) } s = append(s, args...) if len(s) > 0 && len(args) == 0 { s = append(s, "") } return strings.Join(s, " ") }
go
func commandChain(chain []*cli.Command, args []string) string { s := make([]string, 0) for _, c := range chain { s = append(s, c.Command) } s = append(s, args...) if len(s) > 0 && len(args) == 0 { s = append(s, "") } return strings.Join(s, " ") }
[ "func", "commandChain", "(", "chain", "[", "]", "*", "cli", ".", "Command", ",", "args", "[", "]", "string", ")", "string", "{", "s", ":=", "make", "(", "[", "]", "string", ",", "0", ")", "\n", "for", "_", ",", "c", ":=", "range", "chain", "{", "s", "=", "append", "(", "s", ",", "c", ".", "Command", ")", "\n", "}", "\n", "s", "=", "append", "(", "s", ",", "args", "...", ")", "\n", "if", "len", "(", "s", ")", ">", "0", "&&", "len", "(", "args", ")", "==", "0", "{", "s", "=", "append", "(", "s", ",", "\"\"", ")", "\n", "}", "\n", "return", "strings", ".", "Join", "(", "s", ",", "\" \"", ")", "\n", "}" ]
// commandChain builds a command chain from the given command slice.
[ "commandChain", "builds", "a", "command", "chain", "from", "the", "given", "command", "slice", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/binaries/seesaw_cli/main.go#L93-L103
train
google/seesaw
binaries/seesaw_cli/main.go
autoComplete
func autoComplete(line string, pos int, key rune) (string, int, bool) { switch key { case 0x01: // Ctrl-A return line, 0, true case 0x03: // Ctrl-C exit() case 0x05: // Ctrl-E return line, len(line), true case 0x09: // Ctrl-I (Tab) _, _, chain, args := cli.FindCommand(string(line)) line := commandChain(chain, args) return line, len(line), true case 0x15: // Ctrl-U return "", 0, true case 0x1a: // Ctrl-Z suspend() case '?': cmd, subcmds, chain, args := cli.FindCommand(string(line[0:pos])) if cmd == nil { term.Write([]byte(prompt)) term.Write([]byte(line)) term.Write([]byte("?\n")) } if subcmds != nil { for _, c := range *subcmds { term.Write([]byte(" " + c.Command)) term.Write([]byte("\n")) } } else if cmd == nil { term.Write([]byte("Unknown command.\n")) } line := commandChain(chain, args) return line, len(line), true } return "", 0, false }
go
func autoComplete(line string, pos int, key rune) (string, int, bool) { switch key { case 0x01: // Ctrl-A return line, 0, true case 0x03: // Ctrl-C exit() case 0x05: // Ctrl-E return line, len(line), true case 0x09: // Ctrl-I (Tab) _, _, chain, args := cli.FindCommand(string(line)) line := commandChain(chain, args) return line, len(line), true case 0x15: // Ctrl-U return "", 0, true case 0x1a: // Ctrl-Z suspend() case '?': cmd, subcmds, chain, args := cli.FindCommand(string(line[0:pos])) if cmd == nil { term.Write([]byte(prompt)) term.Write([]byte(line)) term.Write([]byte("?\n")) } if subcmds != nil { for _, c := range *subcmds { term.Write([]byte(" " + c.Command)) term.Write([]byte("\n")) } } else if cmd == nil { term.Write([]byte("Unknown command.\n")) } line := commandChain(chain, args) return line, len(line), true } return "", 0, false }
[ "func", "autoComplete", "(", "line", "string", ",", "pos", "int", ",", "key", "rune", ")", "(", "string", ",", "int", ",", "bool", ")", "{", "switch", "key", "{", "case", "0x01", ":", "return", "line", ",", "0", ",", "true", "\n", "case", "0x03", ":", "exit", "(", ")", "\n", "case", "0x05", ":", "return", "line", ",", "len", "(", "line", ")", ",", "true", "\n", "case", "0x09", ":", "_", ",", "_", ",", "chain", ",", "args", ":=", "cli", ".", "FindCommand", "(", "string", "(", "line", ")", ")", "\n", "line", ":=", "commandChain", "(", "chain", ",", "args", ")", "\n", "return", "line", ",", "len", "(", "line", ")", ",", "true", "\n", "case", "0x15", ":", "return", "\"\"", ",", "0", ",", "true", "\n", "case", "0x1a", ":", "suspend", "(", ")", "\n", "case", "'?'", ":", "cmd", ",", "subcmds", ",", "chain", ",", "args", ":=", "cli", ".", "FindCommand", "(", "string", "(", "line", "[", "0", ":", "pos", "]", ")", ")", "\n", "if", "cmd", "==", "nil", "{", "term", ".", "Write", "(", "[", "]", "byte", "(", "prompt", ")", ")", "\n", "term", ".", "Write", "(", "[", "]", "byte", "(", "line", ")", ")", "\n", "term", ".", "Write", "(", "[", "]", "byte", "(", "\"?\\n\"", ")", ")", "\n", "}", "\n", "\\n", "\n", "if", "subcmds", "!=", "nil", "{", "for", "_", ",", "c", ":=", "range", "*", "subcmds", "{", "term", ".", "Write", "(", "[", "]", "byte", "(", "\" \"", "+", "c", ".", "Command", ")", ")", "\n", "term", ".", "Write", "(", "[", "]", "byte", "(", "\"\\n\"", ")", ")", "\n", "}", "\n", "}", "else", "\\n", "\n", "if", "cmd", "==", "nil", "{", "term", ".", "Write", "(", "[", "]", "byte", "(", "\"Unknown command.\\n\"", ")", ")", "\n", "}", "\n", "}", "\n", "\\n", "\n", "}" ]
// autoComplete attempts to complete the user's input when certain // characters are typed.
[ "autoComplete", "attempts", "to", "complete", "the", "user", "s", "input", "when", "certain", "characters", "are", "typed", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/binaries/seesaw_cli/main.go#L107-L143
train
google/seesaw
binaries/seesaw_cli/main.go
interactive
func interactive() { status, err := seesawConn.ClusterStatus() if err != nil { fatalf("Failed to get cluster status: %v", err) } fmt.Printf("\nSeesaw CLI - Engine version %d\n\n", status.Version) u, err := user.Current() if err != nil { fatalf("Failed to get current user: %v", err) } ha, err := seesawConn.HAStatus() if err != nil { fatalf("Failed to get HA status: %v", err) } if ha.State != seesaw.HAMaster { fmt.Println("WARNING: This seesaw is not currently the master.") } prompt = fmt.Sprintf("%s@%s> ", u.Username, status.Site) // Setup signal handler before we switch to a raw terminal. sigc := make(chan os.Signal, 3) signal.Notify(sigc, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM) go func() { <-sigc exit() }() terminalInit() for { cmdline, err := term.ReadLine() if err != nil { break } cmdline = strings.TrimSpace(cmdline) if cmdline == "" { continue } if err := seesawCLI.Execute(cmdline); err != nil { fmt.Println(err) } } }
go
func interactive() { status, err := seesawConn.ClusterStatus() if err != nil { fatalf("Failed to get cluster status: %v", err) } fmt.Printf("\nSeesaw CLI - Engine version %d\n\n", status.Version) u, err := user.Current() if err != nil { fatalf("Failed to get current user: %v", err) } ha, err := seesawConn.HAStatus() if err != nil { fatalf("Failed to get HA status: %v", err) } if ha.State != seesaw.HAMaster { fmt.Println("WARNING: This seesaw is not currently the master.") } prompt = fmt.Sprintf("%s@%s> ", u.Username, status.Site) // Setup signal handler before we switch to a raw terminal. sigc := make(chan os.Signal, 3) signal.Notify(sigc, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM) go func() { <-sigc exit() }() terminalInit() for { cmdline, err := term.ReadLine() if err != nil { break } cmdline = strings.TrimSpace(cmdline) if cmdline == "" { continue } if err := seesawCLI.Execute(cmdline); err != nil { fmt.Println(err) } } }
[ "func", "interactive", "(", ")", "{", "status", ",", "err", ":=", "seesawConn", ".", "ClusterStatus", "(", ")", "\n", "if", "err", "!=", "nil", "{", "fatalf", "(", "\"Failed to get cluster status: %v\"", ",", "err", ")", "\n", "}", "\n", "fmt", ".", "Printf", "(", "\"\\nSeesaw CLI - Engine version %d\\n\\n\"", ",", "\\n", ")", "\n", "\\n", "\n", "\\n", "\n", "status", ".", "Version", "\n", "u", ",", "err", ":=", "user", ".", "Current", "(", ")", "\n", "if", "err", "!=", "nil", "{", "fatalf", "(", "\"Failed to get current user: %v\"", ",", "err", ")", "\n", "}", "\n", "ha", ",", "err", ":=", "seesawConn", ".", "HAStatus", "(", ")", "\n", "if", "err", "!=", "nil", "{", "fatalf", "(", "\"Failed to get HA status: %v\"", ",", "err", ")", "\n", "}", "\n", "if", "ha", ".", "State", "!=", "seesaw", ".", "HAMaster", "{", "fmt", ".", "Println", "(", "\"WARNING: This seesaw is not currently the master.\"", ")", "\n", "}", "\n", "prompt", "=", "fmt", ".", "Sprintf", "(", "\"%s@%s> \"", ",", "u", ".", "Username", ",", "status", ".", "Site", ")", "\n", "sigc", ":=", "make", "(", "chan", "os", ".", "Signal", ",", "3", ")", "\n", "signal", ".", "Notify", "(", "sigc", ",", "syscall", ".", "SIGINT", ",", "syscall", ".", "SIGQUIT", ",", "syscall", ".", "SIGTERM", ")", "\n", "}" ]
// interactive invokes the interactive CLI interface.
[ "interactive", "invokes", "the", "interactive", "CLI", "interface", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/binaries/seesaw_cli/main.go#L146-L191
train
google/seesaw
ipvs/ipvs.go
newIPVSService
func newIPVSService(svc *Service) *ipvsService { ipvsSvc := &ipvsService{ Address: svc.Address, Protocol: svc.Protocol, Port: svc.Port, FirewallMark: svc.FirewallMark, Scheduler: svc.Scheduler, Flags: svc.Flags, Timeout: svc.Timeout, PersistenceEngine: svc.PersistenceEngine, } if ip4 := svc.Address.To4(); ip4 != nil { ipvsSvc.AddrFamily = syscall.AF_INET ipvsSvc.Netmask = 0xffffffff } else { ipvsSvc.AddrFamily = syscall.AF_INET6 ipvsSvc.Netmask = 128 } return ipvsSvc }
go
func newIPVSService(svc *Service) *ipvsService { ipvsSvc := &ipvsService{ Address: svc.Address, Protocol: svc.Protocol, Port: svc.Port, FirewallMark: svc.FirewallMark, Scheduler: svc.Scheduler, Flags: svc.Flags, Timeout: svc.Timeout, PersistenceEngine: svc.PersistenceEngine, } if ip4 := svc.Address.To4(); ip4 != nil { ipvsSvc.AddrFamily = syscall.AF_INET ipvsSvc.Netmask = 0xffffffff } else { ipvsSvc.AddrFamily = syscall.AF_INET6 ipvsSvc.Netmask = 128 } return ipvsSvc }
[ "func", "newIPVSService", "(", "svc", "*", "Service", ")", "*", "ipvsService", "{", "ipvsSvc", ":=", "&", "ipvsService", "{", "Address", ":", "svc", ".", "Address", ",", "Protocol", ":", "svc", ".", "Protocol", ",", "Port", ":", "svc", ".", "Port", ",", "FirewallMark", ":", "svc", ".", "FirewallMark", ",", "Scheduler", ":", "svc", ".", "Scheduler", ",", "Flags", ":", "svc", ".", "Flags", ",", "Timeout", ":", "svc", ".", "Timeout", ",", "PersistenceEngine", ":", "svc", ".", "PersistenceEngine", ",", "}", "\n", "if", "ip4", ":=", "svc", ".", "Address", ".", "To4", "(", ")", ";", "ip4", "!=", "nil", "{", "ipvsSvc", ".", "AddrFamily", "=", "syscall", ".", "AF_INET", "\n", "ipvsSvc", ".", "Netmask", "=", "0xffffffff", "\n", "}", "else", "{", "ipvsSvc", ".", "AddrFamily", "=", "syscall", ".", "AF_INET6", "\n", "ipvsSvc", ".", "Netmask", "=", "128", "\n", "}", "\n", "return", "ipvsSvc", "\n", "}" ]
// newIPVSService converts a service to its IPVS representation.
[ "newIPVSService", "converts", "a", "service", "to", "its", "IPVS", "representation", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L81-L102
train
google/seesaw
ipvs/ipvs.go
newIPVSDestination
func newIPVSDestination(dst *Destination) *ipvsDestination { return &ipvsDestination{ Address: dst.Address, Port: dst.Port, Flags: dst.Flags, Weight: uint32(dst.Weight), UpperThreshold: dst.UpperThreshold, LowerThreshold: dst.LowerThreshold, } }
go
func newIPVSDestination(dst *Destination) *ipvsDestination { return &ipvsDestination{ Address: dst.Address, Port: dst.Port, Flags: dst.Flags, Weight: uint32(dst.Weight), UpperThreshold: dst.UpperThreshold, LowerThreshold: dst.LowerThreshold, } }
[ "func", "newIPVSDestination", "(", "dst", "*", "Destination", ")", "*", "ipvsDestination", "{", "return", "&", "ipvsDestination", "{", "Address", ":", "dst", ".", "Address", ",", "Port", ":", "dst", ".", "Port", ",", "Flags", ":", "dst", ".", "Flags", ",", "Weight", ":", "uint32", "(", "dst", ".", "Weight", ")", ",", "UpperThreshold", ":", "dst", ".", "UpperThreshold", ",", "LowerThreshold", ":", "dst", ".", "LowerThreshold", ",", "}", "\n", "}" ]
// newIPVSDestination converts a destination to its IPVS representation.
[ "newIPVSDestination", "converts", "a", "destination", "to", "its", "IPVS", "representation", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L105-L114
train
google/seesaw
ipvs/ipvs.go
toService
func (ipvsSvc ipvsService) toService() *Service { svc := &Service{ Address: ipvsSvc.Address, Protocol: ipvsSvc.Protocol, Port: ipvsSvc.Port, FirewallMark: ipvsSvc.FirewallMark, Scheduler: ipvsSvc.Scheduler, Flags: ipvsSvc.Flags, Timeout: ipvsSvc.Timeout, PersistenceEngine: ipvsSvc.PersistenceEngine, Statistics: &ServiceStats{}, } // Various callers of this package expect that a service will always // have a non-nil address (all zero bytes if non-existent). At some // point we may want to revisit this and return a nil address instead. if svc.Address == nil { if ipvsSvc.AddrFamily == syscall.AF_INET { svc.Address = net.IPv4zero } else { svc.Address = net.IPv6zero } } if ipvsSvc.Stats != nil { *svc.Statistics = *ipvsSvc.Stats } return svc }
go
func (ipvsSvc ipvsService) toService() *Service { svc := &Service{ Address: ipvsSvc.Address, Protocol: ipvsSvc.Protocol, Port: ipvsSvc.Port, FirewallMark: ipvsSvc.FirewallMark, Scheduler: ipvsSvc.Scheduler, Flags: ipvsSvc.Flags, Timeout: ipvsSvc.Timeout, PersistenceEngine: ipvsSvc.PersistenceEngine, Statistics: &ServiceStats{}, } // Various callers of this package expect that a service will always // have a non-nil address (all zero bytes if non-existent). At some // point we may want to revisit this and return a nil address instead. if svc.Address == nil { if ipvsSvc.AddrFamily == syscall.AF_INET { svc.Address = net.IPv4zero } else { svc.Address = net.IPv6zero } } if ipvsSvc.Stats != nil { *svc.Statistics = *ipvsSvc.Stats } return svc }
[ "func", "(", "ipvsSvc", "ipvsService", ")", "toService", "(", ")", "*", "Service", "{", "svc", ":=", "&", "Service", "{", "Address", ":", "ipvsSvc", ".", "Address", ",", "Protocol", ":", "ipvsSvc", ".", "Protocol", ",", "Port", ":", "ipvsSvc", ".", "Port", ",", "FirewallMark", ":", "ipvsSvc", ".", "FirewallMark", ",", "Scheduler", ":", "ipvsSvc", ".", "Scheduler", ",", "Flags", ":", "ipvsSvc", ".", "Flags", ",", "Timeout", ":", "ipvsSvc", ".", "Timeout", ",", "PersistenceEngine", ":", "ipvsSvc", ".", "PersistenceEngine", ",", "Statistics", ":", "&", "ServiceStats", "{", "}", ",", "}", "\n", "if", "svc", ".", "Address", "==", "nil", "{", "if", "ipvsSvc", ".", "AddrFamily", "==", "syscall", ".", "AF_INET", "{", "svc", ".", "Address", "=", "net", ".", "IPv4zero", "\n", "}", "else", "{", "svc", ".", "Address", "=", "net", ".", "IPv6zero", "\n", "}", "\n", "}", "\n", "if", "ipvsSvc", ".", "Stats", "!=", "nil", "{", "*", "svc", ".", "Statistics", "=", "*", "ipvsSvc", ".", "Stats", "\n", "}", "\n", "return", "svc", "\n", "}" ]
// toService converts a service entry from its IPVS representation to the Go // equivalent Service structure.
[ "toService", "converts", "a", "service", "entry", "from", "its", "IPVS", "representation", "to", "the", "Go", "equivalent", "Service", "structure", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L118-L147
train
google/seesaw
ipvs/ipvs.go
toDestination
func (ipvsDst ipvsDestination) toDestination() *Destination { dst := &Destination{ Address: ipvsDst.Address, Port: ipvsDst.Port, Weight: int32(ipvsDst.Weight), // TODO(jsing): uint32? Flags: ipvsDst.Flags, LowerThreshold: ipvsDst.LowerThreshold, UpperThreshold: ipvsDst.UpperThreshold, Statistics: &DestinationStats{}, } if ipvsDst.Stats != nil { *dst.Statistics = *ipvsDst.Stats } dst.Statistics.ActiveConns = ipvsDst.ActiveConns dst.Statistics.InactiveConns = ipvsDst.InactiveConns dst.Statistics.PersistConns = ipvsDst.PersistConns return dst }
go
func (ipvsDst ipvsDestination) toDestination() *Destination { dst := &Destination{ Address: ipvsDst.Address, Port: ipvsDst.Port, Weight: int32(ipvsDst.Weight), // TODO(jsing): uint32? Flags: ipvsDst.Flags, LowerThreshold: ipvsDst.LowerThreshold, UpperThreshold: ipvsDst.UpperThreshold, Statistics: &DestinationStats{}, } if ipvsDst.Stats != nil { *dst.Statistics = *ipvsDst.Stats } dst.Statistics.ActiveConns = ipvsDst.ActiveConns dst.Statistics.InactiveConns = ipvsDst.InactiveConns dst.Statistics.PersistConns = ipvsDst.PersistConns return dst }
[ "func", "(", "ipvsDst", "ipvsDestination", ")", "toDestination", "(", ")", "*", "Destination", "{", "dst", ":=", "&", "Destination", "{", "Address", ":", "ipvsDst", ".", "Address", ",", "Port", ":", "ipvsDst", ".", "Port", ",", "Weight", ":", "int32", "(", "ipvsDst", ".", "Weight", ")", ",", "Flags", ":", "ipvsDst", ".", "Flags", ",", "LowerThreshold", ":", "ipvsDst", ".", "LowerThreshold", ",", "UpperThreshold", ":", "ipvsDst", ".", "UpperThreshold", ",", "Statistics", ":", "&", "DestinationStats", "{", "}", ",", "}", "\n", "if", "ipvsDst", ".", "Stats", "!=", "nil", "{", "*", "dst", ".", "Statistics", "=", "*", "ipvsDst", ".", "Stats", "\n", "}", "\n", "dst", ".", "Statistics", ".", "ActiveConns", "=", "ipvsDst", ".", "ActiveConns", "\n", "dst", ".", "Statistics", ".", "InactiveConns", "=", "ipvsDst", ".", "InactiveConns", "\n", "dst", ".", "Statistics", ".", "PersistConns", "=", "ipvsDst", ".", "PersistConns", "\n", "return", "dst", "\n", "}" ]
// toDestination converts a destination entry from its IPVS representation // to the Go equivalent Destination structure.
[ "toDestination", "converts", "a", "destination", "entry", "from", "its", "IPVS", "representation", "to", "the", "Go", "equivalent", "Destination", "structure", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L151-L171
train
google/seesaw
ipvs/ipvs.go
Bytes
func (f ServiceFlags) Bytes() []byte { x := make([]byte, 8) var b [4]byte *(*uint32)(unsafe.Pointer(&b)) = uint32(f) copy(x[:4], b[:]) *(*uint32)(unsafe.Pointer(&b)) = ^uint32(0) copy(x[4:], b[:]) return x }
go
func (f ServiceFlags) Bytes() []byte { x := make([]byte, 8) var b [4]byte *(*uint32)(unsafe.Pointer(&b)) = uint32(f) copy(x[:4], b[:]) *(*uint32)(unsafe.Pointer(&b)) = ^uint32(0) copy(x[4:], b[:]) return x }
[ "func", "(", "f", "ServiceFlags", ")", "Bytes", "(", ")", "[", "]", "byte", "{", "x", ":=", "make", "(", "[", "]", "byte", ",", "8", ")", "\n", "var", "b", "[", "4", "]", "byte", "\n", "*", "(", "*", "uint32", ")", "(", "unsafe", ".", "Pointer", "(", "&", "b", ")", ")", "=", "uint32", "(", "f", ")", "\n", "copy", "(", "x", "[", ":", "4", "]", ",", "b", "[", ":", "]", ")", "\n", "*", "(", "*", "uint32", ")", "(", "unsafe", ".", "Pointer", "(", "&", "b", ")", ")", "=", "^", "uint32", "(", "0", ")", "\n", "copy", "(", "x", "[", "4", ":", "]", ",", "b", "[", ":", "]", ")", "\n", "return", "x", "\n", "}" ]
// Bytes returns the netlink representation of the service flags.
[ "Bytes", "returns", "the", "netlink", "representation", "of", "the", "service", "flags", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L203-L211
train
google/seesaw
ipvs/ipvs.go
SetBytes
func (f *ServiceFlags) SetBytes(x []byte) { var b [4]byte copy(b[:], x) *f = ServiceFlags(*(*uint32)(unsafe.Pointer(&b))) }
go
func (f *ServiceFlags) SetBytes(x []byte) { var b [4]byte copy(b[:], x) *f = ServiceFlags(*(*uint32)(unsafe.Pointer(&b))) }
[ "func", "(", "f", "*", "ServiceFlags", ")", "SetBytes", "(", "x", "[", "]", "byte", ")", "{", "var", "b", "[", "4", "]", "byte", "\n", "copy", "(", "b", "[", ":", "]", ",", "x", ")", "\n", "*", "f", "=", "ServiceFlags", "(", "*", "(", "*", "uint32", ")", "(", "unsafe", ".", "Pointer", "(", "&", "b", ")", ")", ")", "\n", "}" ]
// SetBytes sets the service flags from its netlink representation.
[ "SetBytes", "sets", "the", "service", "flags", "from", "its", "netlink", "representation", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L214-L218
train
google/seesaw
ipvs/ipvs.go
Equal
func (svc Service) Equal(other Service) bool { return svc.Address.Equal(other.Address) && svc.Protocol == other.Protocol && svc.Port == other.Port && svc.FirewallMark == other.FirewallMark && svc.Scheduler == other.Scheduler && svc.Flags == other.Flags && svc.Timeout == other.Timeout && svc.PersistenceEngine == other.PersistenceEngine }
go
func (svc Service) Equal(other Service) bool { return svc.Address.Equal(other.Address) && svc.Protocol == other.Protocol && svc.Port == other.Port && svc.FirewallMark == other.FirewallMark && svc.Scheduler == other.Scheduler && svc.Flags == other.Flags && svc.Timeout == other.Timeout && svc.PersistenceEngine == other.PersistenceEngine }
[ "func", "(", "svc", "Service", ")", "Equal", "(", "other", "Service", ")", "bool", "{", "return", "svc", ".", "Address", ".", "Equal", "(", "other", ".", "Address", ")", "&&", "svc", ".", "Protocol", "==", "other", ".", "Protocol", "&&", "svc", ".", "Port", "==", "other", ".", "Port", "&&", "svc", ".", "FirewallMark", "==", "other", ".", "FirewallMark", "&&", "svc", ".", "Scheduler", "==", "other", ".", "Scheduler", "&&", "svc", ".", "Flags", "==", "other", ".", "Flags", "&&", "svc", ".", "Timeout", "==", "other", ".", "Timeout", "&&", "svc", ".", "PersistenceEngine", "==", "other", ".", "PersistenceEngine", "\n", "}" ]
// Equal returns true if two Services are the same.
[ "Equal", "returns", "true", "if", "two", "Services", "are", "the", "same", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L241-L250
train
google/seesaw
ipvs/ipvs.go
String
func (svc Service) String() string { switch { case svc.FirewallMark > 0: return fmt.Sprintf("FWM %d (%s)", svc.FirewallMark, svc.Scheduler) case svc.Address.To4() == nil: return fmt.Sprintf("%v [%v]:%d (%s)", svc.Protocol, svc.Address, svc.Port, svc.Scheduler) default: return fmt.Sprintf("%v %v:%d (%s)", svc.Protocol, svc.Address, svc.Port, svc.Scheduler) } }
go
func (svc Service) String() string { switch { case svc.FirewallMark > 0: return fmt.Sprintf("FWM %d (%s)", svc.FirewallMark, svc.Scheduler) case svc.Address.To4() == nil: return fmt.Sprintf("%v [%v]:%d (%s)", svc.Protocol, svc.Address, svc.Port, svc.Scheduler) default: return fmt.Sprintf("%v %v:%d (%s)", svc.Protocol, svc.Address, svc.Port, svc.Scheduler) } }
[ "func", "(", "svc", "Service", ")", "String", "(", ")", "string", "{", "switch", "{", "case", "svc", ".", "FirewallMark", ">", "0", ":", "return", "fmt", ".", "Sprintf", "(", "\"FWM %d (%s)\"", ",", "svc", ".", "FirewallMark", ",", "svc", ".", "Scheduler", ")", "\n", "case", "svc", ".", "Address", ".", "To4", "(", ")", "==", "nil", ":", "return", "fmt", ".", "Sprintf", "(", "\"%v [%v]:%d (%s)\"", ",", "svc", ".", "Protocol", ",", "svc", ".", "Address", ",", "svc", ".", "Port", ",", "svc", ".", "Scheduler", ")", "\n", "default", ":", "return", "fmt", ".", "Sprintf", "(", "\"%v %v:%d (%s)\"", ",", "svc", ".", "Protocol", ",", "svc", ".", "Address", ",", "svc", ".", "Port", ",", "svc", ".", "Scheduler", ")", "\n", "}", "\n", "}" ]
// String returns a string representation of a Service.
[ "String", "returns", "a", "string", "representation", "of", "a", "Service", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L253-L262
train
google/seesaw
ipvs/ipvs.go
Equal
func (dest Destination) Equal(other Destination) bool { return dest.Address.Equal(other.Address) && dest.Port == other.Port && dest.Weight == other.Weight && dest.Flags == other.Flags && dest.LowerThreshold == other.LowerThreshold && dest.UpperThreshold == other.UpperThreshold }
go
func (dest Destination) Equal(other Destination) bool { return dest.Address.Equal(other.Address) && dest.Port == other.Port && dest.Weight == other.Weight && dest.Flags == other.Flags && dest.LowerThreshold == other.LowerThreshold && dest.UpperThreshold == other.UpperThreshold }
[ "func", "(", "dest", "Destination", ")", "Equal", "(", "other", "Destination", ")", "bool", "{", "return", "dest", ".", "Address", ".", "Equal", "(", "other", ".", "Address", ")", "&&", "dest", ".", "Port", "==", "other", ".", "Port", "&&", "dest", ".", "Weight", "==", "other", ".", "Weight", "&&", "dest", ".", "Flags", "==", "other", ".", "Flags", "&&", "dest", ".", "LowerThreshold", "==", "other", ".", "LowerThreshold", "&&", "dest", ".", "UpperThreshold", "==", "other", ".", "UpperThreshold", "\n", "}" ]
// Equal returns true if two Destinations are the same.
[ "Equal", "returns", "true", "if", "two", "Destinations", "are", "the", "same", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L288-L295
train
google/seesaw
ipvs/ipvs.go
String
func (dest Destination) String() string { addr := dest.Address.String() if dest.Address.To4() == nil { addr = fmt.Sprintf("[%s]", addr) } return fmt.Sprintf("%s:%d", addr, dest.Port) }
go
func (dest Destination) String() string { addr := dest.Address.String() if dest.Address.To4() == nil { addr = fmt.Sprintf("[%s]", addr) } return fmt.Sprintf("%s:%d", addr, dest.Port) }
[ "func", "(", "dest", "Destination", ")", "String", "(", ")", "string", "{", "addr", ":=", "dest", ".", "Address", ".", "String", "(", ")", "\n", "if", "dest", ".", "Address", ".", "To4", "(", ")", "==", "nil", "{", "addr", "=", "fmt", ".", "Sprintf", "(", "\"[%s]\"", ",", "addr", ")", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"%s:%d\"", ",", "addr", ",", "dest", ".", "Port", ")", "\n", "}" ]
// String returns a string representation of a Destination.
[ "String", "returns", "a", "string", "representation", "of", "a", "Destination", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L298-L304
train
google/seesaw
ipvs/ipvs.go
Init
func Init() error { var err error family, err = netlink.Family(familyName) if err != nil { return err } return netlink.SendMessageUnmarshal(C.IPVS_CMD_GET_INFO, family, 0, &info) }
go
func Init() error { var err error family, err = netlink.Family(familyName) if err != nil { return err } return netlink.SendMessageUnmarshal(C.IPVS_CMD_GET_INFO, family, 0, &info) }
[ "func", "Init", "(", ")", "error", "{", "var", "err", "error", "\n", "family", ",", "err", "=", "netlink", ".", "Family", "(", "familyName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "netlink", ".", "SendMessageUnmarshal", "(", "C", ".", "IPVS_CMD_GET_INFO", ",", "family", ",", "0", ",", "&", "info", ")", "\n", "}" ]
// Init intialises IPVS.
[ "Init", "intialises", "IPVS", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L356-L364
train
google/seesaw
ipvs/ipvs.go
Version
func Version() IPVSVersion { v := uint(info.Version) return IPVSVersion{ Major: (v >> 16) & 0xff, Minor: (v >> 8) & 0xff, Patch: v & 0xff, } }
go
func Version() IPVSVersion { v := uint(info.Version) return IPVSVersion{ Major: (v >> 16) & 0xff, Minor: (v >> 8) & 0xff, Patch: v & 0xff, } }
[ "func", "Version", "(", ")", "IPVSVersion", "{", "v", ":=", "uint", "(", "info", ".", "Version", ")", "\n", "return", "IPVSVersion", "{", "Major", ":", "(", "v", ">>", "16", ")", "&", "0xff", ",", "Minor", ":", "(", "v", ">>", "8", ")", "&", "0xff", ",", "Patch", ":", "v", "&", "0xff", ",", "}", "\n", "}" ]
// Version returns the version number for IPVS.
[ "Version", "returns", "the", "version", "number", "for", "IPVS", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L367-L374
train
google/seesaw
ipvs/ipvs.go
AddService
func AddService(svc Service) error { ic := &ipvsCommand{Service: newIPVSService(&svc)} if err := netlink.SendMessageMarshalled(C.IPVS_CMD_NEW_SERVICE, family, 0, ic); err != nil { return err } for _, dst := range svc.Destinations { if err := AddDestination(svc, *dst); err != nil { return err } } return nil }
go
func AddService(svc Service) error { ic := &ipvsCommand{Service: newIPVSService(&svc)} if err := netlink.SendMessageMarshalled(C.IPVS_CMD_NEW_SERVICE, family, 0, ic); err != nil { return err } for _, dst := range svc.Destinations { if err := AddDestination(svc, *dst); err != nil { return err } } return nil }
[ "func", "AddService", "(", "svc", "Service", ")", "error", "{", "ic", ":=", "&", "ipvsCommand", "{", "Service", ":", "newIPVSService", "(", "&", "svc", ")", "}", "\n", "if", "err", ":=", "netlink", ".", "SendMessageMarshalled", "(", "C", ".", "IPVS_CMD_NEW_SERVICE", ",", "family", ",", "0", ",", "ic", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "for", "_", ",", "dst", ":=", "range", "svc", ".", "Destinations", "{", "if", "err", ":=", "AddDestination", "(", "svc", ",", "*", "dst", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// AddService adds the specified service to the IPVS table. Any destinations // associated with the given service will also be added.
[ "AddService", "adds", "the", "specified", "service", "to", "the", "IPVS", "table", ".", "Any", "destinations", "associated", "with", "the", "given", "service", "will", "also", "be", "added", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L383-L394
train
google/seesaw
ipvs/ipvs.go
UpdateService
func UpdateService(svc Service) error { ic := &ipvsCommand{Service: newIPVSService(&svc)} return netlink.SendMessageMarshalled(C.IPVS_CMD_SET_SERVICE, family, 0, ic) }
go
func UpdateService(svc Service) error { ic := &ipvsCommand{Service: newIPVSService(&svc)} return netlink.SendMessageMarshalled(C.IPVS_CMD_SET_SERVICE, family, 0, ic) }
[ "func", "UpdateService", "(", "svc", "Service", ")", "error", "{", "ic", ":=", "&", "ipvsCommand", "{", "Service", ":", "newIPVSService", "(", "&", "svc", ")", "}", "\n", "return", "netlink", ".", "SendMessageMarshalled", "(", "C", ".", "IPVS_CMD_SET_SERVICE", ",", "family", ",", "0", ",", "ic", ")", "\n", "}" ]
// UpdateService updates the specified service in the IPVS table.
[ "UpdateService", "updates", "the", "specified", "service", "in", "the", "IPVS", "table", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L397-L400
train
google/seesaw
ipvs/ipvs.go
DeleteService
func DeleteService(svc Service) error { ic := &ipvsCommand{Service: newIPVSService(&svc)} return netlink.SendMessageMarshalled(C.IPVS_CMD_DEL_SERVICE, family, 0, ic) }
go
func DeleteService(svc Service) error { ic := &ipvsCommand{Service: newIPVSService(&svc)} return netlink.SendMessageMarshalled(C.IPVS_CMD_DEL_SERVICE, family, 0, ic) }
[ "func", "DeleteService", "(", "svc", "Service", ")", "error", "{", "ic", ":=", "&", "ipvsCommand", "{", "Service", ":", "newIPVSService", "(", "&", "svc", ")", "}", "\n", "return", "netlink", ".", "SendMessageMarshalled", "(", "C", ".", "IPVS_CMD_DEL_SERVICE", ",", "family", ",", "0", ",", "ic", ")", "\n", "}" ]
// DeleteService deletes the specified service from the IPVS table.
[ "DeleteService", "deletes", "the", "specified", "service", "from", "the", "IPVS", "table", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L403-L406
train
google/seesaw
ipvs/ipvs.go
AddDestination
func AddDestination(svc Service, dst Destination) error { ic := &ipvsCommand{ Service: newIPVSService(&svc), Destination: newIPVSDestination(&dst), } return netlink.SendMessageMarshalled(C.IPVS_CMD_NEW_DEST, family, 0, ic) }
go
func AddDestination(svc Service, dst Destination) error { ic := &ipvsCommand{ Service: newIPVSService(&svc), Destination: newIPVSDestination(&dst), } return netlink.SendMessageMarshalled(C.IPVS_CMD_NEW_DEST, family, 0, ic) }
[ "func", "AddDestination", "(", "svc", "Service", ",", "dst", "Destination", ")", "error", "{", "ic", ":=", "&", "ipvsCommand", "{", "Service", ":", "newIPVSService", "(", "&", "svc", ")", ",", "Destination", ":", "newIPVSDestination", "(", "&", "dst", ")", ",", "}", "\n", "return", "netlink", ".", "SendMessageMarshalled", "(", "C", ".", "IPVS_CMD_NEW_DEST", ",", "family", ",", "0", ",", "ic", ")", "\n", "}" ]
// AddDestination adds the specified destination to the IPVS table.
[ "AddDestination", "adds", "the", "specified", "destination", "to", "the", "IPVS", "table", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L409-L415
train
google/seesaw
ipvs/ipvs.go
UpdateDestination
func UpdateDestination(svc Service, dst Destination) error { ic := &ipvsCommand{ Service: newIPVSService(&svc), Destination: newIPVSDestination(&dst), } return netlink.SendMessageMarshalled(C.IPVS_CMD_SET_DEST, family, 0, ic) }
go
func UpdateDestination(svc Service, dst Destination) error { ic := &ipvsCommand{ Service: newIPVSService(&svc), Destination: newIPVSDestination(&dst), } return netlink.SendMessageMarshalled(C.IPVS_CMD_SET_DEST, family, 0, ic) }
[ "func", "UpdateDestination", "(", "svc", "Service", ",", "dst", "Destination", ")", "error", "{", "ic", ":=", "&", "ipvsCommand", "{", "Service", ":", "newIPVSService", "(", "&", "svc", ")", ",", "Destination", ":", "newIPVSDestination", "(", "&", "dst", ")", ",", "}", "\n", "return", "netlink", ".", "SendMessageMarshalled", "(", "C", ".", "IPVS_CMD_SET_DEST", ",", "family", ",", "0", ",", "ic", ")", "\n", "}" ]
// UpdateDestination updates the specified destination in the IPVS table.
[ "UpdateDestination", "updates", "the", "specified", "destination", "in", "the", "IPVS", "table", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L418-L424
train
google/seesaw
ipvs/ipvs.go
DeleteDestination
func DeleteDestination(svc Service, dst Destination) error { ic := &ipvsCommand{ Service: newIPVSService(&svc), Destination: newIPVSDestination(&dst), } return netlink.SendMessageMarshalled(C.IPVS_CMD_DEL_DEST, family, 0, ic) }
go
func DeleteDestination(svc Service, dst Destination) error { ic := &ipvsCommand{ Service: newIPVSService(&svc), Destination: newIPVSDestination(&dst), } return netlink.SendMessageMarshalled(C.IPVS_CMD_DEL_DEST, family, 0, ic) }
[ "func", "DeleteDestination", "(", "svc", "Service", ",", "dst", "Destination", ")", "error", "{", "ic", ":=", "&", "ipvsCommand", "{", "Service", ":", "newIPVSService", "(", "&", "svc", ")", ",", "Destination", ":", "newIPVSDestination", "(", "&", "dst", ")", ",", "}", "\n", "return", "netlink", ".", "SendMessageMarshalled", "(", "C", ".", "IPVS_CMD_DEL_DEST", ",", "family", ",", "0", ",", "ic", ")", "\n", "}" ]
// DeleteDestination deletes the specified destination from the IPVS table.
[ "DeleteDestination", "deletes", "the", "specified", "destination", "from", "the", "IPVS", "table", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L427-L433
train
google/seesaw
ipvs/ipvs.go
destinations
func destinations(svc *Service) ([]*Destination, error) { msg, err := netlink.NewMessage(C.IPVS_CMD_GET_DEST, family, netlink.MFDump) if err != nil { return nil, err } defer msg.Free() ic := &ipvsCommand{Service: newIPVSService(svc)} if err := msg.Marshal(ic); err != nil { return nil, err } var dsts []*Destination cb := func(msg *netlink.Message, arg interface{}) error { ic := &ipvsCommand{} if err := msg.Unmarshal(ic); err != nil { return fmt.Errorf("failed to unmarshal service: %v", err) } if ic.Destination == nil { return errors.New("no destination in unmarshalled message") } dsts = append(dsts, ic.Destination.toDestination()) return nil } if err := msg.SendCallback(cb, nil); err != nil { return nil, err } return dsts, nil }
go
func destinations(svc *Service) ([]*Destination, error) { msg, err := netlink.NewMessage(C.IPVS_CMD_GET_DEST, family, netlink.MFDump) if err != nil { return nil, err } defer msg.Free() ic := &ipvsCommand{Service: newIPVSService(svc)} if err := msg.Marshal(ic); err != nil { return nil, err } var dsts []*Destination cb := func(msg *netlink.Message, arg interface{}) error { ic := &ipvsCommand{} if err := msg.Unmarshal(ic); err != nil { return fmt.Errorf("failed to unmarshal service: %v", err) } if ic.Destination == nil { return errors.New("no destination in unmarshalled message") } dsts = append(dsts, ic.Destination.toDestination()) return nil } if err := msg.SendCallback(cb, nil); err != nil { return nil, err } return dsts, nil }
[ "func", "destinations", "(", "svc", "*", "Service", ")", "(", "[", "]", "*", "Destination", ",", "error", ")", "{", "msg", ",", "err", ":=", "netlink", ".", "NewMessage", "(", "C", ".", "IPVS_CMD_GET_DEST", ",", "family", ",", "netlink", ".", "MFDump", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "msg", ".", "Free", "(", ")", "\n", "ic", ":=", "&", "ipvsCommand", "{", "Service", ":", "newIPVSService", "(", "svc", ")", "}", "\n", "if", "err", ":=", "msg", ".", "Marshal", "(", "ic", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "var", "dsts", "[", "]", "*", "Destination", "\n", "cb", ":=", "func", "(", "msg", "*", "netlink", ".", "Message", ",", "arg", "interface", "{", "}", ")", "error", "{", "ic", ":=", "&", "ipvsCommand", "{", "}", "\n", "if", "err", ":=", "msg", ".", "Unmarshal", "(", "ic", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"failed to unmarshal service: %v\"", ",", "err", ")", "\n", "}", "\n", "if", "ic", ".", "Destination", "==", "nil", "{", "return", "errors", ".", "New", "(", "\"no destination in unmarshalled message\"", ")", "\n", "}", "\n", "dsts", "=", "append", "(", "dsts", ",", "ic", ".", "Destination", ".", "toDestination", "(", ")", ")", "\n", "return", "nil", "\n", "}", "\n", "if", "err", ":=", "msg", ".", "SendCallback", "(", "cb", ",", "nil", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "dsts", ",", "nil", "\n", "}" ]
// destinations returns a list of destinations that are currently // configured in the kernel IPVS table for the specified service.
[ "destinations", "returns", "a", "list", "of", "destinations", "that", "are", "currently", "configured", "in", "the", "kernel", "IPVS", "table", "for", "the", "specified", "service", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L437-L465
train
google/seesaw
ipvs/ipvs.go
services
func services(svc *Service) ([]*Service, error) { var flags int if svc == nil { flags = netlink.MFDump } msg, err := netlink.NewMessage(C.IPVS_CMD_GET_SERVICE, family, flags) if err != nil { return nil, err } defer msg.Free() if svc != nil { ic := &ipvsCommand{Service: newIPVSService(svc)} if err := msg.Marshal(ic); err != nil { return nil, err } } var svcs []*Service cb := func(msg *netlink.Message, arg interface{}) error { ic := &ipvsCommand{} if err := msg.Unmarshal(ic); err != nil { return fmt.Errorf("failed to unmarshal service: %v", err) } if ic.Service == nil { return errors.New("no service in unmarshalled message") } svcs = append(svcs, ic.Service.toService()) return nil } if err := msg.SendCallback(cb, nil); err != nil { return nil, err } for _, svc := range svcs { dsts, err := destinations(svc) if err != nil { return nil, err } svc.Destinations = dsts } return svcs, nil }
go
func services(svc *Service) ([]*Service, error) { var flags int if svc == nil { flags = netlink.MFDump } msg, err := netlink.NewMessage(C.IPVS_CMD_GET_SERVICE, family, flags) if err != nil { return nil, err } defer msg.Free() if svc != nil { ic := &ipvsCommand{Service: newIPVSService(svc)} if err := msg.Marshal(ic); err != nil { return nil, err } } var svcs []*Service cb := func(msg *netlink.Message, arg interface{}) error { ic := &ipvsCommand{} if err := msg.Unmarshal(ic); err != nil { return fmt.Errorf("failed to unmarshal service: %v", err) } if ic.Service == nil { return errors.New("no service in unmarshalled message") } svcs = append(svcs, ic.Service.toService()) return nil } if err := msg.SendCallback(cb, nil); err != nil { return nil, err } for _, svc := range svcs { dsts, err := destinations(svc) if err != nil { return nil, err } svc.Destinations = dsts } return svcs, nil }
[ "func", "services", "(", "svc", "*", "Service", ")", "(", "[", "]", "*", "Service", ",", "error", ")", "{", "var", "flags", "int", "\n", "if", "svc", "==", "nil", "{", "flags", "=", "netlink", ".", "MFDump", "\n", "}", "\n", "msg", ",", "err", ":=", "netlink", ".", "NewMessage", "(", "C", ".", "IPVS_CMD_GET_SERVICE", ",", "family", ",", "flags", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "msg", ".", "Free", "(", ")", "\n", "if", "svc", "!=", "nil", "{", "ic", ":=", "&", "ipvsCommand", "{", "Service", ":", "newIPVSService", "(", "svc", ")", "}", "\n", "if", "err", ":=", "msg", ".", "Marshal", "(", "ic", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "var", "svcs", "[", "]", "*", "Service", "\n", "cb", ":=", "func", "(", "msg", "*", "netlink", ".", "Message", ",", "arg", "interface", "{", "}", ")", "error", "{", "ic", ":=", "&", "ipvsCommand", "{", "}", "\n", "if", "err", ":=", "msg", ".", "Unmarshal", "(", "ic", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"failed to unmarshal service: %v\"", ",", "err", ")", "\n", "}", "\n", "if", "ic", ".", "Service", "==", "nil", "{", "return", "errors", ".", "New", "(", "\"no service in unmarshalled message\"", ")", "\n", "}", "\n", "svcs", "=", "append", "(", "svcs", ",", "ic", ".", "Service", ".", "toService", "(", ")", ")", "\n", "return", "nil", "\n", "}", "\n", "if", "err", ":=", "msg", ".", "SendCallback", "(", "cb", ",", "nil", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "for", "_", ",", "svc", ":=", "range", "svcs", "{", "dsts", ",", "err", ":=", "destinations", "(", "svc", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "svc", ".", "Destinations", "=", "dsts", "\n", "}", "\n", "return", "svcs", ",", "nil", "\n", "}" ]
// services returns a list of services that are currently configured in the // kernel IPVS table. If a specific service is given, an exact match will be // attempted and a single service will be returned if it is found.
[ "services", "returns", "a", "list", "of", "services", "that", "are", "currently", "configured", "in", "the", "kernel", "IPVS", "table", ".", "If", "a", "specific", "service", "is", "given", "an", "exact", "match", "will", "be", "attempted", "and", "a", "single", "service", "will", "be", "returned", "if", "it", "is", "found", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L470-L514
train
google/seesaw
ipvs/ipvs.go
GetService
func GetService(svc *Service) (*Service, error) { svcs, err := services(svc) if err != nil { return nil, err } if len(svcs) == 0 { return nil, errors.New("no service found") } return svcs[0], nil }
go
func GetService(svc *Service) (*Service, error) { svcs, err := services(svc) if err != nil { return nil, err } if len(svcs) == 0 { return nil, errors.New("no service found") } return svcs[0], nil }
[ "func", "GetService", "(", "svc", "*", "Service", ")", "(", "*", "Service", ",", "error", ")", "{", "svcs", ",", "err", ":=", "services", "(", "svc", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "len", "(", "svcs", ")", "==", "0", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"no service found\"", ")", "\n", "}", "\n", "return", "svcs", "[", "0", "]", ",", "nil", "\n", "}" ]
// GetService returns the service entry that is currently configured in the // kernel IPVS table, which matches the specified service.
[ "GetService", "returns", "the", "service", "entry", "that", "is", "currently", "configured", "in", "the", "kernel", "IPVS", "table", "which", "matches", "the", "specified", "service", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L518-L527
train
google/seesaw
common/conn/ipc.go
HAStatus
func (c *engineIPC) HAStatus() (*seesaw.HAStatus, error) { var ha seesaw.HAStatus if err := c.client.Call("SeesawEngine.HAStatus", c.ctx, &ha); err != nil { return nil, err } return &ha, nil }
go
func (c *engineIPC) HAStatus() (*seesaw.HAStatus, error) { var ha seesaw.HAStatus if err := c.client.Call("SeesawEngine.HAStatus", c.ctx, &ha); err != nil { return nil, err } return &ha, nil }
[ "func", "(", "c", "*", "engineIPC", ")", "HAStatus", "(", ")", "(", "*", "seesaw", ".", "HAStatus", ",", "error", ")", "{", "var", "ha", "seesaw", ".", "HAStatus", "\n", "if", "err", ":=", "c", ".", "client", ".", "Call", "(", "\"SeesawEngine.HAStatus\"", ",", "c", ".", "ctx", ",", "&", "ha", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "ha", ",", "nil", "\n", "}" ]
// HAStatus requests the HA status of the Seesaw Node.
[ "HAStatus", "requests", "the", "HA", "status", "of", "the", "Seesaw", "Node", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/conn/ipc.go#L85-L91
train
google/seesaw
common/conn/ipc.go
ConfigSource
func (c *engineIPC) ConfigSource(source string) (string, error) { cs := &ipc.ConfigSource{c.ctx, source} if err := c.client.Call("SeesawEngine.ConfigSource", cs, &source); err != nil { return "", err } return source, nil }
go
func (c *engineIPC) ConfigSource(source string) (string, error) { cs := &ipc.ConfigSource{c.ctx, source} if err := c.client.Call("SeesawEngine.ConfigSource", cs, &source); err != nil { return "", err } return source, nil }
[ "func", "(", "c", "*", "engineIPC", ")", "ConfigSource", "(", "source", "string", ")", "(", "string", ",", "error", ")", "{", "cs", ":=", "&", "ipc", ".", "ConfigSource", "{", "c", ".", "ctx", ",", "source", "}", "\n", "if", "err", ":=", "c", ".", "client", ".", "Call", "(", "\"SeesawEngine.ConfigSource\"", ",", "cs", ",", "&", "source", ")", ";", "err", "!=", "nil", "{", "return", "\"\"", ",", "err", "\n", "}", "\n", "return", "source", ",", "nil", "\n", "}" ]
// ConfigSource requests the configuration source be changed to the // specified source. An empty string results in the source remaining // unchanged. The current configuration source is returned.
[ "ConfigSource", "requests", "the", "configuration", "source", "be", "changed", "to", "the", "specified", "source", ".", "An", "empty", "string", "results", "in", "the", "source", "remaining", "unchanged", ".", "The", "current", "configuration", "source", "is", "returned", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/conn/ipc.go#L96-L102
train
google/seesaw
common/conn/ipc.go
BGPNeighbors
func (c *engineIPC) BGPNeighbors() ([]*quagga.Neighbor, error) { var bn quagga.Neighbors if err := c.client.Call("SeesawEngine.BGPNeighbors", c.ctx, &bn); err != nil { return nil, err } return bn.Neighbors, nil }
go
func (c *engineIPC) BGPNeighbors() ([]*quagga.Neighbor, error) { var bn quagga.Neighbors if err := c.client.Call("SeesawEngine.BGPNeighbors", c.ctx, &bn); err != nil { return nil, err } return bn.Neighbors, nil }
[ "func", "(", "c", "*", "engineIPC", ")", "BGPNeighbors", "(", ")", "(", "[", "]", "*", "quagga", ".", "Neighbor", ",", "error", ")", "{", "var", "bn", "quagga", ".", "Neighbors", "\n", "if", "err", ":=", "c", ".", "client", ".", "Call", "(", "\"SeesawEngine.BGPNeighbors\"", ",", "c", ".", "ctx", ",", "&", "bn", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "bn", ".", "Neighbors", ",", "nil", "\n", "}" ]
// BGPNeighbors requests a list of all BGP neighbors that this seesaw is // peering with.
[ "BGPNeighbors", "requests", "a", "list", "of", "all", "BGP", "neighbors", "that", "this", "seesaw", "is", "peering", "with", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/conn/ipc.go#L111-L117
train
google/seesaw
common/conn/ipc.go
VLANs
func (c *engineIPC) VLANs() (*seesaw.VLANs, error) { var v seesaw.VLANs if err := c.client.Call("SeesawEngine.VLANs", c.ctx, &v); err != nil { return nil, err } return &v, nil }
go
func (c *engineIPC) VLANs() (*seesaw.VLANs, error) { var v seesaw.VLANs if err := c.client.Call("SeesawEngine.VLANs", c.ctx, &v); err != nil { return nil, err } return &v, nil }
[ "func", "(", "c", "*", "engineIPC", ")", "VLANs", "(", ")", "(", "*", "seesaw", ".", "VLANs", ",", "error", ")", "{", "var", "v", "seesaw", ".", "VLANs", "\n", "if", "err", ":=", "c", ".", "client", ".", "Call", "(", "\"SeesawEngine.VLANs\"", ",", "c", ".", "ctx", ",", "&", "v", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "v", ",", "nil", "\n", "}" ]
// VLANs requests a list of VLANs configured on the cluster.
[ "VLANs", "requests", "a", "list", "of", "VLANs", "configured", "on", "the", "cluster", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/conn/ipc.go#L120-L126
train
google/seesaw
common/conn/ipc.go
Vservers
func (c *engineIPC) Vservers() (map[string]*seesaw.Vserver, error) { var vm seesaw.VserverMap if err := c.client.Call("SeesawEngine.Vservers", c.ctx, &vm); err != nil { return nil, err } return vm.Vservers, nil }
go
func (c *engineIPC) Vservers() (map[string]*seesaw.Vserver, error) { var vm seesaw.VserverMap if err := c.client.Call("SeesawEngine.Vservers", c.ctx, &vm); err != nil { return nil, err } return vm.Vservers, nil }
[ "func", "(", "c", "*", "engineIPC", ")", "Vservers", "(", ")", "(", "map", "[", "string", "]", "*", "seesaw", ".", "Vserver", ",", "error", ")", "{", "var", "vm", "seesaw", ".", "VserverMap", "\n", "if", "err", ":=", "c", ".", "client", ".", "Call", "(", "\"SeesawEngine.Vservers\"", ",", "c", ".", "ctx", ",", "&", "vm", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "vm", ".", "Vservers", ",", "nil", "\n", "}" ]
// Vservers requests a list of all vservers that are configured on the cluster.
[ "Vservers", "requests", "a", "list", "of", "all", "vservers", "that", "are", "configured", "on", "the", "cluster", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/conn/ipc.go#L129-L135
train
google/seesaw
common/conn/ipc.go
OverrideVserver
func (c *engineIPC) OverrideVserver(vserver *seesaw.VserverOverride) error { override := &ipc.Override{Ctx: c.ctx, Vserver: vserver} return c.client.Call("SeesawEngine.OverrideVserver", override, nil) }
go
func (c *engineIPC) OverrideVserver(vserver *seesaw.VserverOverride) error { override := &ipc.Override{Ctx: c.ctx, Vserver: vserver} return c.client.Call("SeesawEngine.OverrideVserver", override, nil) }
[ "func", "(", "c", "*", "engineIPC", ")", "OverrideVserver", "(", "vserver", "*", "seesaw", ".", "VserverOverride", ")", "error", "{", "override", ":=", "&", "ipc", ".", "Override", "{", "Ctx", ":", "c", ".", "ctx", ",", "Vserver", ":", "vserver", "}", "\n", "return", "c", ".", "client", ".", "Call", "(", "\"SeesawEngine.OverrideVserver\"", ",", "override", ",", "nil", ")", "\n", "}" ]
// OverrideVserver requests that the specified VserverOverride be applied.
[ "OverrideVserver", "requests", "that", "the", "specified", "VserverOverride", "be", "applied", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/conn/ipc.go#L159-L162
train
google/seesaw
ha/engine_client.go
HAConfig
func (e *EngineClient) HAConfig() (*seesaw.HAConfig, error) { engineConn, err := net.DialTimeout("unix", e.Socket, engineTimeout) if err != nil { return nil, fmt.Errorf("HAConfig: Dial failed: %v", err) } engineConn.SetDeadline(time.Now().Add(engineTimeout)) engine := rpc.NewClient(engineConn) defer engine.Close() var config seesaw.HAConfig ctx := ipc.NewTrustedContext(seesaw.SCHA) if err := engine.Call("SeesawEngine.HAConfig", ctx, &config); err != nil { return nil, fmt.Errorf("HAConfig: SeesawEngine.HAConfig failed: %v", err) } return &config, nil }
go
func (e *EngineClient) HAConfig() (*seesaw.HAConfig, error) { engineConn, err := net.DialTimeout("unix", e.Socket, engineTimeout) if err != nil { return nil, fmt.Errorf("HAConfig: Dial failed: %v", err) } engineConn.SetDeadline(time.Now().Add(engineTimeout)) engine := rpc.NewClient(engineConn) defer engine.Close() var config seesaw.HAConfig ctx := ipc.NewTrustedContext(seesaw.SCHA) if err := engine.Call("SeesawEngine.HAConfig", ctx, &config); err != nil { return nil, fmt.Errorf("HAConfig: SeesawEngine.HAConfig failed: %v", err) } return &config, nil }
[ "func", "(", "e", "*", "EngineClient", ")", "HAConfig", "(", ")", "(", "*", "seesaw", ".", "HAConfig", ",", "error", ")", "{", "engineConn", ",", "err", ":=", "net", ".", "DialTimeout", "(", "\"unix\"", ",", "e", ".", "Socket", ",", "engineTimeout", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"HAConfig: Dial failed: %v\"", ",", "err", ")", "\n", "}", "\n", "engineConn", ".", "SetDeadline", "(", "time", ".", "Now", "(", ")", ".", "Add", "(", "engineTimeout", ")", ")", "\n", "engine", ":=", "rpc", ".", "NewClient", "(", "engineConn", ")", "\n", "defer", "engine", ".", "Close", "(", ")", "\n", "var", "config", "seesaw", ".", "HAConfig", "\n", "ctx", ":=", "ipc", ".", "NewTrustedContext", "(", "seesaw", ".", "SCHA", ")", "\n", "if", "err", ":=", "engine", ".", "Call", "(", "\"SeesawEngine.HAConfig\"", ",", "ctx", ",", "&", "config", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"HAConfig: SeesawEngine.HAConfig failed: %v\"", ",", "err", ")", "\n", "}", "\n", "return", "&", "config", ",", "nil", "\n", "}" ]
// HAConfig requests the HAConfig from the Seesaw Engine.
[ "HAConfig", "requests", "the", "HAConfig", "from", "the", "Seesaw", "Engine", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ha/engine_client.go#L47-L62
train
google/seesaw
ha/engine_client.go
HAUpdate
func (e *EngineClient) HAUpdate(status seesaw.HAStatus) (bool, error) { engineConn, err := net.DialTimeout("unix", e.Socket, engineTimeout) if err != nil { return false, fmt.Errorf("HAUpdate: Dial failed: %v", err) } engineConn.SetDeadline(time.Now().Add(engineTimeout)) engine := rpc.NewClient(engineConn) defer engine.Close() var failover bool ctx := ipc.NewTrustedContext(seesaw.SCHA) if err := engine.Call("SeesawEngine.HAUpdate", &ipc.HAStatus{ctx, status}, &failover); err != nil { return false, fmt.Errorf("HAUpdate: SeesawEngine.HAUpdate failed: %v", err) } return failover, nil }
go
func (e *EngineClient) HAUpdate(status seesaw.HAStatus) (bool, error) { engineConn, err := net.DialTimeout("unix", e.Socket, engineTimeout) if err != nil { return false, fmt.Errorf("HAUpdate: Dial failed: %v", err) } engineConn.SetDeadline(time.Now().Add(engineTimeout)) engine := rpc.NewClient(engineConn) defer engine.Close() var failover bool ctx := ipc.NewTrustedContext(seesaw.SCHA) if err := engine.Call("SeesawEngine.HAUpdate", &ipc.HAStatus{ctx, status}, &failover); err != nil { return false, fmt.Errorf("HAUpdate: SeesawEngine.HAUpdate failed: %v", err) } return failover, nil }
[ "func", "(", "e", "*", "EngineClient", ")", "HAUpdate", "(", "status", "seesaw", ".", "HAStatus", ")", "(", "bool", ",", "error", ")", "{", "engineConn", ",", "err", ":=", "net", ".", "DialTimeout", "(", "\"unix\"", ",", "e", ".", "Socket", ",", "engineTimeout", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "fmt", ".", "Errorf", "(", "\"HAUpdate: Dial failed: %v\"", ",", "err", ")", "\n", "}", "\n", "engineConn", ".", "SetDeadline", "(", "time", ".", "Now", "(", ")", ".", "Add", "(", "engineTimeout", ")", ")", "\n", "engine", ":=", "rpc", ".", "NewClient", "(", "engineConn", ")", "\n", "defer", "engine", ".", "Close", "(", ")", "\n", "var", "failover", "bool", "\n", "ctx", ":=", "ipc", ".", "NewTrustedContext", "(", "seesaw", ".", "SCHA", ")", "\n", "if", "err", ":=", "engine", ".", "Call", "(", "\"SeesawEngine.HAUpdate\"", ",", "&", "ipc", ".", "HAStatus", "{", "ctx", ",", "status", "}", ",", "&", "failover", ")", ";", "err", "!=", "nil", "{", "return", "false", ",", "fmt", ".", "Errorf", "(", "\"HAUpdate: SeesawEngine.HAUpdate failed: %v\"", ",", "err", ")", "\n", "}", "\n", "return", "failover", ",", "nil", "\n", "}" ]
// HAUpdate informs the Seesaw Engine of the current HAStatus. // The Seesaw Engine may request a failover in response.
[ "HAUpdate", "informs", "the", "Seesaw", "Engine", "of", "the", "current", "HAStatus", ".", "The", "Seesaw", "Engine", "may", "request", "a", "failover", "in", "response", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ha/engine_client.go#L84-L99
train
google/seesaw
ha/engine_client.go
HAUpdate
func (e *DummyEngine) HAUpdate(status seesaw.HAStatus) (bool, error) { return false, nil }
go
func (e *DummyEngine) HAUpdate(status seesaw.HAStatus) (bool, error) { return false, nil }
[ "func", "(", "e", "*", "DummyEngine", ")", "HAUpdate", "(", "status", "seesaw", ".", "HAStatus", ")", "(", "bool", ",", "error", ")", "{", "return", "false", ",", "nil", "\n", "}" ]
// HAUpdate does nothing.
[ "HAUpdate", "does", "nothing", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ha/engine_client.go#L117-L119
train
google/seesaw
common/server/server.go
signalName
func signalName(s syscall.Signal) string { if name, ok := signalNames[s]; ok { return name } return fmt.Sprintf("SIG %d", s) }
go
func signalName(s syscall.Signal) string { if name, ok := signalNames[s]; ok { return name } return fmt.Sprintf("SIG %d", s) }
[ "func", "signalName", "(", "s", "syscall", ".", "Signal", ")", "string", "{", "if", "name", ",", "ok", ":=", "signalNames", "[", "s", "]", ";", "ok", "{", "return", "name", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"SIG %d\"", ",", "s", ")", "\n", "}" ]
// signalName returns a string containing the standard name for a given signal.
[ "signalName", "returns", "a", "string", "containing", "the", "standard", "name", "for", "a", "given", "signal", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/server/server.go#L48-L53
train
google/seesaw
common/server/server.go
ShutdownHandler
func ShutdownHandler(server Shutdowner) { sigc := make(chan os.Signal, 3) signal.Notify(sigc, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM) go func() { for s := range sigc { name := s.String() if sig, ok := s.(syscall.Signal); ok { name = signalName(sig) } log.Infof("Received %v, initiating shutdown...", name) server.Shutdown() } }() }
go
func ShutdownHandler(server Shutdowner) { sigc := make(chan os.Signal, 3) signal.Notify(sigc, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM) go func() { for s := range sigc { name := s.String() if sig, ok := s.(syscall.Signal); ok { name = signalName(sig) } log.Infof("Received %v, initiating shutdown...", name) server.Shutdown() } }() }
[ "func", "ShutdownHandler", "(", "server", "Shutdowner", ")", "{", "sigc", ":=", "make", "(", "chan", "os", ".", "Signal", ",", "3", ")", "\n", "signal", ".", "Notify", "(", "sigc", ",", "syscall", ".", "SIGINT", ",", "syscall", ".", "SIGQUIT", ",", "syscall", ".", "SIGTERM", ")", "\n", "go", "func", "(", ")", "{", "for", "s", ":=", "range", "sigc", "{", "name", ":=", "s", ".", "String", "(", ")", "\n", "if", "sig", ",", "ok", ":=", "s", ".", "(", "syscall", ".", "Signal", ")", ";", "ok", "{", "name", "=", "signalName", "(", "sig", ")", "\n", "}", "\n", "log", ".", "Infof", "(", "\"Received %v, initiating shutdown...\"", ",", "name", ")", "\n", "server", ".", "Shutdown", "(", ")", "\n", "}", "\n", "}", "(", ")", "\n", "}" ]
// ShutdownHandler configures signal handling and initiates a shutdown if a // SIGINT, SIGQUIT or SIGTERM is received by the process.
[ "ShutdownHandler", "configures", "signal", "handling", "and", "initiates", "a", "shutdown", "if", "a", "SIGINT", "SIGQUIT", "or", "SIGTERM", "is", "received", "by", "the", "process", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/server/server.go#L57-L70
train
google/seesaw
common/server/server.go
RemoveUnixSocket
func RemoveUnixSocket(socket string) error { if _, err := os.Stat(socket); err == nil { c, err := net.DialTimeout("unix", socket, 5*time.Second) if err == nil { c.Close() return fmt.Errorf("Socket %v is in use", socket) } log.Infof("Removing stale socket %v", socket) return os.Remove(socket) } return nil }
go
func RemoveUnixSocket(socket string) error { if _, err := os.Stat(socket); err == nil { c, err := net.DialTimeout("unix", socket, 5*time.Second) if err == nil { c.Close() return fmt.Errorf("Socket %v is in use", socket) } log.Infof("Removing stale socket %v", socket) return os.Remove(socket) } return nil }
[ "func", "RemoveUnixSocket", "(", "socket", "string", ")", "error", "{", "if", "_", ",", "err", ":=", "os", ".", "Stat", "(", "socket", ")", ";", "err", "==", "nil", "{", "c", ",", "err", ":=", "net", ".", "DialTimeout", "(", "\"unix\"", ",", "socket", ",", "5", "*", "time", ".", "Second", ")", "\n", "if", "err", "==", "nil", "{", "c", ".", "Close", "(", ")", "\n", "return", "fmt", ".", "Errorf", "(", "\"Socket %v is in use\"", ",", "socket", ")", "\n", "}", "\n", "log", ".", "Infof", "(", "\"Removing stale socket %v\"", ",", "socket", ")", "\n", "return", "os", ".", "Remove", "(", "socket", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// RemoveUnixSocket checks to see if the given socket already exists and // removes it if nothing responds to connections.
[ "RemoveUnixSocket", "checks", "to", "see", "if", "the", "given", "socket", "already", "exists", "and", "removes", "it", "if", "nothing", "responds", "to", "connections", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/server/server.go#L74-L85
train
google/seesaw
common/server/server.go
ServerRunDirectory
func ServerRunDirectory(server string, owner, group int) error { serverRunDir := path.Join(seesaw.RunPath, server) if err := os.MkdirAll(seesaw.RunPath, 0755); err != nil { return fmt.Errorf("Failed to make run directory: %v", err) } if err := os.MkdirAll(serverRunDir, 0700); err != nil { return fmt.Errorf("Failed to make run directory: %v", err) } if err := os.Chown(serverRunDir, owner, group); err != nil { return fmt.Errorf("Failed to change ownership on run directory: %v", err) } if err := os.Chmod(serverRunDir, 0770); err != nil { return fmt.Errorf("Failed to change permissions on run directory: %v", err) } return nil }
go
func ServerRunDirectory(server string, owner, group int) error { serverRunDir := path.Join(seesaw.RunPath, server) if err := os.MkdirAll(seesaw.RunPath, 0755); err != nil { return fmt.Errorf("Failed to make run directory: %v", err) } if err := os.MkdirAll(serverRunDir, 0700); err != nil { return fmt.Errorf("Failed to make run directory: %v", err) } if err := os.Chown(serverRunDir, owner, group); err != nil { return fmt.Errorf("Failed to change ownership on run directory: %v", err) } if err := os.Chmod(serverRunDir, 0770); err != nil { return fmt.Errorf("Failed to change permissions on run directory: %v", err) } return nil }
[ "func", "ServerRunDirectory", "(", "server", "string", ",", "owner", ",", "group", "int", ")", "error", "{", "serverRunDir", ":=", "path", ".", "Join", "(", "seesaw", ".", "RunPath", ",", "server", ")", "\n", "if", "err", ":=", "os", ".", "MkdirAll", "(", "seesaw", ".", "RunPath", ",", "0755", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"Failed to make run directory: %v\"", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "os", ".", "MkdirAll", "(", "serverRunDir", ",", "0700", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"Failed to make run directory: %v\"", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "os", ".", "Chown", "(", "serverRunDir", ",", "owner", ",", "group", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"Failed to change ownership on run directory: %v\"", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "os", ".", "Chmod", "(", "serverRunDir", ",", "0770", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"Failed to change permissions on run directory: %v\"", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// ServerRunDirectory ensures that the run directory exists and has the // appropriate ownership and permissions.
[ "ServerRunDirectory", "ensures", "that", "the", "run", "directory", "exists", "and", "has", "the", "appropriate", "ownership", "and", "permissions", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/server/server.go#L89-L104
train
google/seesaw
common/server/server.go
RPCAccept
func RPCAccept(ln net.Listener, server *rpc.Server) error { errClosing := errors.New("use of closed network connection") for { conn, err := ln.Accept() if err != nil { if ne, ok := err.(net.Error); ok && ne.Temporary() { log.Warningf("RPC accept temporary error: %v", err) time.Sleep(1 * time.Second) continue } if oe, ok := err.(*net.OpError); ok && oe.Err.Error() == errClosing.Error() { log.Infoln("RPC accept connection closed") return nil } log.Errorf("RPC accept error: %v", err) return err } go server.ServeConn(conn) } }
go
func RPCAccept(ln net.Listener, server *rpc.Server) error { errClosing := errors.New("use of closed network connection") for { conn, err := ln.Accept() if err != nil { if ne, ok := err.(net.Error); ok && ne.Temporary() { log.Warningf("RPC accept temporary error: %v", err) time.Sleep(1 * time.Second) continue } if oe, ok := err.(*net.OpError); ok && oe.Err.Error() == errClosing.Error() { log.Infoln("RPC accept connection closed") return nil } log.Errorf("RPC accept error: %v", err) return err } go server.ServeConn(conn) } }
[ "func", "RPCAccept", "(", "ln", "net", ".", "Listener", ",", "server", "*", "rpc", ".", "Server", ")", "error", "{", "errClosing", ":=", "errors", ".", "New", "(", "\"use of closed network connection\"", ")", "\n", "for", "{", "conn", ",", "err", ":=", "ln", ".", "Accept", "(", ")", "\n", "if", "err", "!=", "nil", "{", "if", "ne", ",", "ok", ":=", "err", ".", "(", "net", ".", "Error", ")", ";", "ok", "&&", "ne", ".", "Temporary", "(", ")", "{", "log", ".", "Warningf", "(", "\"RPC accept temporary error: %v\"", ",", "err", ")", "\n", "time", ".", "Sleep", "(", "1", "*", "time", ".", "Second", ")", "\n", "continue", "\n", "}", "\n", "if", "oe", ",", "ok", ":=", "err", ".", "(", "*", "net", ".", "OpError", ")", ";", "ok", "&&", "oe", ".", "Err", ".", "Error", "(", ")", "==", "errClosing", ".", "Error", "(", ")", "{", "log", ".", "Infoln", "(", "\"RPC accept connection closed\"", ")", "\n", "return", "nil", "\n", "}", "\n", "log", ".", "Errorf", "(", "\"RPC accept error: %v\"", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n", "go", "server", ".", "ServeConn", "(", "conn", ")", "\n", "}", "\n", "}" ]
// RPCAccept accepts connections on the listener and dispatches them to the // RPC server for service. Unfortunately the native Go rpc.Accept function // fatals on any accept error, including temporary failures and closure of // the listener.
[ "RPCAccept", "accepts", "connections", "on", "the", "listener", "and", "dispatches", "them", "to", "the", "RPC", "server", "for", "service", ".", "Unfortunately", "the", "native", "Go", "rpc", ".", "Accept", "function", "fatals", "on", "any", "accept", "error", "including", "temporary", "failures", "and", "closure", "of", "the", "listener", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/server/server.go#L110-L129
train
google/seesaw
engine/config/config.go
SourceByName
func SourceByName(name string) (Source, error) { for s, n := range sourceNames { if n == name { return s, nil } } return -1, fmt.Errorf("unknown source %q", name) }
go
func SourceByName(name string) (Source, error) { for s, n := range sourceNames { if n == name { return s, nil } } return -1, fmt.Errorf("unknown source %q", name) }
[ "func", "SourceByName", "(", "name", "string", ")", "(", "Source", ",", "error", ")", "{", "for", "s", ",", "n", ":=", "range", "sourceNames", "{", "if", "n", "==", "name", "{", "return", "s", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "-", "1", ",", "fmt", ".", "Errorf", "(", "\"unknown source %q\"", ",", "name", ")", "\n", "}" ]
// SourceByName returns the source that has the given name.
[ "SourceByName", "returns", "the", "source", "that", "has", "the", "given", "name", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/config/config.go#L62-L69
train
google/seesaw
engine/config/config.go
String
func (s Source) String() string { if name, ok := sourceNames[s]; ok { return name } return "(unknown)" }
go
func (s Source) String() string { if name, ok := sourceNames[s]; ok { return name } return "(unknown)" }
[ "func", "(", "s", "Source", ")", "String", "(", ")", "string", "{", "if", "name", ",", "ok", ":=", "sourceNames", "[", "s", "]", ";", "ok", "{", "return", "name", "\n", "}", "\n", "return", "\"(unknown)\"", "\n", "}" ]
// String returns the string representation of a source.
[ "String", "returns", "the", "string", "representation", "of", "a", "source", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/config/config.go#L72-L77
train
google/seesaw
engine/config/config.go
ReadConfig
func ReadConfig(filename, clusterName string) (*Notification, error) { p := &pb.Cluster{} b, err := ioutil.ReadFile(filename) if err != nil { return nil, err } if err = proto.UnmarshalText(string(b), p); err != nil { return nil, err } c, err := protoToCluster(p, clusterName) if err != nil { return nil, err } return &Notification{c, false, p, SourceDisk, filename, time.Now()}, nil }
go
func ReadConfig(filename, clusterName string) (*Notification, error) { p := &pb.Cluster{} b, err := ioutil.ReadFile(filename) if err != nil { return nil, err } if err = proto.UnmarshalText(string(b), p); err != nil { return nil, err } c, err := protoToCluster(p, clusterName) if err != nil { return nil, err } return &Notification{c, false, p, SourceDisk, filename, time.Now()}, nil }
[ "func", "ReadConfig", "(", "filename", ",", "clusterName", "string", ")", "(", "*", "Notification", ",", "error", ")", "{", "p", ":=", "&", "pb", ".", "Cluster", "{", "}", "\n", "b", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "filename", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "err", "=", "proto", ".", "UnmarshalText", "(", "string", "(", "b", ")", ",", "p", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "c", ",", "err", ":=", "protoToCluster", "(", "p", ",", "clusterName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "Notification", "{", "c", ",", "false", ",", "p", ",", "SourceDisk", ",", "filename", ",", "time", ".", "Now", "(", ")", "}", ",", "nil", "\n", "}" ]
// ReadConfig reads a cluster configuration file.
[ "ReadConfig", "reads", "a", "cluster", "configuration", "file", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/config/config.go#L94-L109
train
google/seesaw
engine/config/config.go
ConfigFromServer
func ConfigFromServer(cluster string) (*Notification, error) { cfg := DefaultEngineConfig() cfg.ClusterName = cluster n := &Notifier{engineCfg: &cfg} return n.configFromServer() }
go
func ConfigFromServer(cluster string) (*Notification, error) { cfg := DefaultEngineConfig() cfg.ClusterName = cluster n := &Notifier{engineCfg: &cfg} return n.configFromServer() }
[ "func", "ConfigFromServer", "(", "cluster", "string", ")", "(", "*", "Notification", ",", "error", ")", "{", "cfg", ":=", "DefaultEngineConfig", "(", ")", "\n", "cfg", ".", "ClusterName", "=", "cluster", "\n", "n", ":=", "&", "Notifier", "{", "engineCfg", ":", "&", "cfg", "}", "\n", "return", "n", ".", "configFromServer", "(", ")", "\n", "}" ]
// ConfigFromServer fetches the cluster configuration for the given cluster.
[ "ConfigFromServer", "fetches", "the", "cluster", "configuration", "for", "the", "given", "cluster", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/config/config.go#L112-L117
train
google/seesaw
engine/config/config.go
pruneArchive
func pruneArchive(archiveDir string, refTime time.Time, max archiveConfig) (*pruneStats, error) { d, err := os.Open(archiveDir) if err != nil { return nil, err } defer d.Close() files, err := d.Readdir(0) if err != nil { return nil, err } sort.Sort(sort.Reverse(byModTime(files))) var seen, curr pruneStats for i := 0; i < len(files); i++ { curr.age = refTime.Sub(files[i].ModTime()) curr.bytes = seen.bytes + files[i].Size() curr.count = seen.count + 1 if curr.count > max.count || curr.bytes > max.bytes || curr.age > max.age { seen.filesRemoved, seen.filesErrored = removeFiles(archiveDir, files[i:]) return &seen, nil } seen = curr } return &seen, nil }
go
func pruneArchive(archiveDir string, refTime time.Time, max archiveConfig) (*pruneStats, error) { d, err := os.Open(archiveDir) if err != nil { return nil, err } defer d.Close() files, err := d.Readdir(0) if err != nil { return nil, err } sort.Sort(sort.Reverse(byModTime(files))) var seen, curr pruneStats for i := 0; i < len(files); i++ { curr.age = refTime.Sub(files[i].ModTime()) curr.bytes = seen.bytes + files[i].Size() curr.count = seen.count + 1 if curr.count > max.count || curr.bytes > max.bytes || curr.age > max.age { seen.filesRemoved, seen.filesErrored = removeFiles(archiveDir, files[i:]) return &seen, nil } seen = curr } return &seen, nil }
[ "func", "pruneArchive", "(", "archiveDir", "string", ",", "refTime", "time", ".", "Time", ",", "max", "archiveConfig", ")", "(", "*", "pruneStats", ",", "error", ")", "{", "d", ",", "err", ":=", "os", ".", "Open", "(", "archiveDir", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "d", ".", "Close", "(", ")", "\n", "files", ",", "err", ":=", "d", ".", "Readdir", "(", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "sort", ".", "Sort", "(", "sort", ".", "Reverse", "(", "byModTime", "(", "files", ")", ")", ")", "\n", "var", "seen", ",", "curr", "pruneStats", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "files", ")", ";", "i", "++", "{", "curr", ".", "age", "=", "refTime", ".", "Sub", "(", "files", "[", "i", "]", ".", "ModTime", "(", ")", ")", "\n", "curr", ".", "bytes", "=", "seen", ".", "bytes", "+", "files", "[", "i", "]", ".", "Size", "(", ")", "\n", "curr", ".", "count", "=", "seen", ".", "count", "+", "1", "\n", "if", "curr", ".", "count", ">", "max", ".", "count", "||", "curr", ".", "bytes", ">", "max", ".", "bytes", "||", "curr", ".", "age", ">", "max", ".", "age", "{", "seen", ".", "filesRemoved", ",", "seen", ".", "filesErrored", "=", "removeFiles", "(", "archiveDir", ",", "files", "[", "i", ":", "]", ")", "\n", "return", "&", "seen", ",", "nil", "\n", "}", "\n", "seen", "=", "curr", "\n", "}", "\n", "return", "&", "seen", ",", "nil", "\n", "}" ]
// pruneArchive removes files from the given directory to ensure that the specified // maximums are not exceeded. It returns the number of the files removed along with // the maximums observed in the current archive.
[ "pruneArchive", "removes", "files", "from", "the", "given", "directory", "to", "ensure", "that", "the", "specified", "maximums", "are", "not", "exceeded", ".", "It", "returns", "the", "number", "of", "the", "files", "removed", "along", "with", "the", "maximums", "observed", "in", "the", "current", "archive", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/config/config.go#L548-L575
train
google/seesaw
ncc/core.go
NewServer
func NewServer(socket string) *Server { return &Server{ nccSocket: socket, shutdown: make(chan bool), } }
go
func NewServer(socket string) *Server { return &Server{ nccSocket: socket, shutdown: make(chan bool), } }
[ "func", "NewServer", "(", "socket", "string", ")", "*", "Server", "{", "return", "&", "Server", "{", "nccSocket", ":", "socket", ",", "shutdown", ":", "make", "(", "chan", "bool", ")", ",", "}", "\n", "}" ]
// NewServer returns an initialised NCC Server struct.
[ "NewServer", "returns", "an", "initialised", "NCC", "Server", "struct", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/core.go#L55-L60
train
google/seesaw
ncc/core.go
Run
func (n *Server) Run() { if err := server.RemoveUnixSocket(n.nccSocket); err != nil { log.Fatalf("Failed to remove socket: %v", err) } ln, err := net.Listen("unix", n.nccSocket) if err != nil { log.Fatalf("listen error: %v", err) } defer ln.Close() defer os.Remove(n.nccSocket) seesawNCC := rpc.NewServer() seesawNCC.Register(&SeesawNCC{}) go server.RPCAccept(ln, seesawNCC) <-n.shutdown }
go
func (n *Server) Run() { if err := server.RemoveUnixSocket(n.nccSocket); err != nil { log.Fatalf("Failed to remove socket: %v", err) } ln, err := net.Listen("unix", n.nccSocket) if err != nil { log.Fatalf("listen error: %v", err) } defer ln.Close() defer os.Remove(n.nccSocket) seesawNCC := rpc.NewServer() seesawNCC.Register(&SeesawNCC{}) go server.RPCAccept(ln, seesawNCC) <-n.shutdown }
[ "func", "(", "n", "*", "Server", ")", "Run", "(", ")", "{", "if", "err", ":=", "server", ".", "RemoveUnixSocket", "(", "n", ".", "nccSocket", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"Failed to remove socket: %v\"", ",", "err", ")", "\n", "}", "\n", "ln", ",", "err", ":=", "net", ".", "Listen", "(", "\"unix\"", ",", "n", ".", "nccSocket", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"listen error: %v\"", ",", "err", ")", "\n", "}", "\n", "defer", "ln", ".", "Close", "(", ")", "\n", "defer", "os", ".", "Remove", "(", "n", ".", "nccSocket", ")", "\n", "seesawNCC", ":=", "rpc", ".", "NewServer", "(", ")", "\n", "seesawNCC", ".", "Register", "(", "&", "SeesawNCC", "{", "}", ")", "\n", "go", "server", ".", "RPCAccept", "(", "ln", ",", "seesawNCC", ")", "\n", "<-", "n", ".", "shutdown", "\n", "}" ]
// Run starts the NCC server.
[ "Run", "starts", "the", "NCC", "server", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/core.go#L63-L79
train
google/seesaw
ha/core.go
NewNode
func NewNode(cfg NodeConfig, conn HAConn, engine Engine) *Node { n := &Node{ NodeConfig: cfg, conn: conn, engine: engine, lastMasterAdvertTime: time.Now(), errChannel: make(chan error), recvChannel: make(chan *advertisement, 20), stopSenderChannel: make(chan seesaw.HAState), shutdownChannel: make(chan bool), } n.setState(seesaw.HABackup) n.resetMasterDownInterval(cfg.MasterAdvertInterval) return n }
go
func NewNode(cfg NodeConfig, conn HAConn, engine Engine) *Node { n := &Node{ NodeConfig: cfg, conn: conn, engine: engine, lastMasterAdvertTime: time.Now(), errChannel: make(chan error), recvChannel: make(chan *advertisement, 20), stopSenderChannel: make(chan seesaw.HAState), shutdownChannel: make(chan bool), } n.setState(seesaw.HABackup) n.resetMasterDownInterval(cfg.MasterAdvertInterval) return n }
[ "func", "NewNode", "(", "cfg", "NodeConfig", ",", "conn", "HAConn", ",", "engine", "Engine", ")", "*", "Node", "{", "n", ":=", "&", "Node", "{", "NodeConfig", ":", "cfg", ",", "conn", ":", "conn", ",", "engine", ":", "engine", ",", "lastMasterAdvertTime", ":", "time", ".", "Now", "(", ")", ",", "errChannel", ":", "make", "(", "chan", "error", ")", ",", "recvChannel", ":", "make", "(", "chan", "*", "advertisement", ",", "20", ")", ",", "stopSenderChannel", ":", "make", "(", "chan", "seesaw", ".", "HAState", ")", ",", "shutdownChannel", ":", "make", "(", "chan", "bool", ")", ",", "}", "\n", "n", ".", "setState", "(", "seesaw", ".", "HABackup", ")", "\n", "n", ".", "resetMasterDownInterval", "(", "cfg", ".", "MasterAdvertInterval", ")", "\n", "return", "n", "\n", "}" ]
// NewNode creates a new Node with the given NodeConfig and HAConn.
[ "NewNode", "creates", "a", "new", "Node", "with", "the", "given", "NodeConfig", "and", "HAConn", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ha/core.go#L93-L107
train
google/seesaw
ha/core.go
resetMasterDownInterval
func (n *Node) resetMasterDownInterval(advertInterval time.Duration) { skewTime := (time.Duration((256 - int(n.Priority))) * (advertInterval)) / 256 masterDownInterval := 3*(advertInterval) + skewTime if masterDownInterval != n.masterDownInterval { n.masterDownInterval = masterDownInterval log.Infof("resetMasterDownInterval: skewTime=%v, masterDownInterval=%v", skewTime, masterDownInterval) } }
go
func (n *Node) resetMasterDownInterval(advertInterval time.Duration) { skewTime := (time.Duration((256 - int(n.Priority))) * (advertInterval)) / 256 masterDownInterval := 3*(advertInterval) + skewTime if masterDownInterval != n.masterDownInterval { n.masterDownInterval = masterDownInterval log.Infof("resetMasterDownInterval: skewTime=%v, masterDownInterval=%v", skewTime, masterDownInterval) } }
[ "func", "(", "n", "*", "Node", ")", "resetMasterDownInterval", "(", "advertInterval", "time", ".", "Duration", ")", "{", "skewTime", ":=", "(", "time", ".", "Duration", "(", "(", "256", "-", "int", "(", "n", ".", "Priority", ")", ")", ")", "*", "(", "advertInterval", ")", ")", "/", "256", "\n", "masterDownInterval", ":=", "3", "*", "(", "advertInterval", ")", "+", "skewTime", "\n", "if", "masterDownInterval", "!=", "n", ".", "masterDownInterval", "{", "n", ".", "masterDownInterval", "=", "masterDownInterval", "\n", "log", ".", "Infof", "(", "\"resetMasterDownInterval: skewTime=%v, masterDownInterval=%v\"", ",", "skewTime", ",", "masterDownInterval", ")", "\n", "}", "\n", "}" ]
// resetMasterDownInterval calculates masterDownInterval per RFC 5798.
[ "resetMasterDownInterval", "calculates", "masterDownInterval", "per", "RFC", "5798", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ha/core.go#L110-L118
train
google/seesaw
ha/core.go
state
func (n *Node) state() seesaw.HAState { n.statusLock.RLock() defer n.statusLock.RUnlock() return n.haStatus.State }
go
func (n *Node) state() seesaw.HAState { n.statusLock.RLock() defer n.statusLock.RUnlock() return n.haStatus.State }
[ "func", "(", "n", "*", "Node", ")", "state", "(", ")", "seesaw", ".", "HAState", "{", "n", ".", "statusLock", ".", "RLock", "(", ")", "\n", "defer", "n", ".", "statusLock", ".", "RUnlock", "(", ")", "\n", "return", "n", ".", "haStatus", ".", "State", "\n", "}" ]
// state returns the current HA state for this node.
[ "state", "returns", "the", "current", "HA", "state", "for", "this", "node", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ha/core.go#L121-L125
train
google/seesaw
ha/core.go
setState
func (n *Node) setState(s seesaw.HAState) { n.statusLock.Lock() defer n.statusLock.Unlock() if n.haStatus.State != s { n.haStatus.State = s n.haStatus.Since = time.Now() n.haStatus.Transitions++ } }
go
func (n *Node) setState(s seesaw.HAState) { n.statusLock.Lock() defer n.statusLock.Unlock() if n.haStatus.State != s { n.haStatus.State = s n.haStatus.Since = time.Now() n.haStatus.Transitions++ } }
[ "func", "(", "n", "*", "Node", ")", "setState", "(", "s", "seesaw", ".", "HAState", ")", "{", "n", ".", "statusLock", ".", "Lock", "(", ")", "\n", "defer", "n", ".", "statusLock", ".", "Unlock", "(", ")", "\n", "if", "n", ".", "haStatus", ".", "State", "!=", "s", "{", "n", ".", "haStatus", ".", "State", "=", "s", "\n", "n", ".", "haStatus", ".", "Since", "=", "time", ".", "Now", "(", ")", "\n", "n", ".", "haStatus", ".", "Transitions", "++", "\n", "}", "\n", "}" ]
// setState changes the HA state for this node.
[ "setState", "changes", "the", "HA", "state", "for", "this", "node", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ha/core.go#L128-L136
train
google/seesaw
ha/core.go
status
func (n *Node) status() seesaw.HAStatus { n.statusLock.Lock() defer n.statusLock.Unlock() n.haStatus.Sent = atomic.LoadUint64(&n.sendCount) n.haStatus.Received = atomic.LoadUint64(&n.receiveCount) n.haStatus.ReceivedQueued = uint64(len(n.recvChannel)) return n.haStatus }
go
func (n *Node) status() seesaw.HAStatus { n.statusLock.Lock() defer n.statusLock.Unlock() n.haStatus.Sent = atomic.LoadUint64(&n.sendCount) n.haStatus.Received = atomic.LoadUint64(&n.receiveCount) n.haStatus.ReceivedQueued = uint64(len(n.recvChannel)) return n.haStatus }
[ "func", "(", "n", "*", "Node", ")", "status", "(", ")", "seesaw", ".", "HAStatus", "{", "n", ".", "statusLock", ".", "Lock", "(", ")", "\n", "defer", "n", ".", "statusLock", ".", "Unlock", "(", ")", "\n", "n", ".", "haStatus", ".", "Sent", "=", "atomic", ".", "LoadUint64", "(", "&", "n", ".", "sendCount", ")", "\n", "n", ".", "haStatus", ".", "Received", "=", "atomic", ".", "LoadUint64", "(", "&", "n", ".", "receiveCount", ")", "\n", "n", ".", "haStatus", ".", "ReceivedQueued", "=", "uint64", "(", "len", "(", "n", ".", "recvChannel", ")", ")", "\n", "return", "n", ".", "haStatus", "\n", "}" ]
// status returns the current HA status for this node.
[ "status", "returns", "the", "current", "HA", "status", "for", "this", "node", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ha/core.go#L139-L146
train
google/seesaw
ha/core.go
newAdvertisement
func (n *Node) newAdvertisement() *advertisement { return &advertisement{ VersionType: vrrpVersionType, VRID: n.VRID, Priority: n.Priority, AdvertInt: uint16(n.MasterAdvertInterval / time.Millisecond / 10), // AdvertInt is in centiseconds } }
go
func (n *Node) newAdvertisement() *advertisement { return &advertisement{ VersionType: vrrpVersionType, VRID: n.VRID, Priority: n.Priority, AdvertInt: uint16(n.MasterAdvertInterval / time.Millisecond / 10), // AdvertInt is in centiseconds } }
[ "func", "(", "n", "*", "Node", ")", "newAdvertisement", "(", ")", "*", "advertisement", "{", "return", "&", "advertisement", "{", "VersionType", ":", "vrrpVersionType", ",", "VRID", ":", "n", ".", "VRID", ",", "Priority", ":", "n", ".", "Priority", ",", "AdvertInt", ":", "uint16", "(", "n", ".", "MasterAdvertInterval", "/", "time", ".", "Millisecond", "/", "10", ")", ",", "}", "\n", "}" ]
// newAdvertisement creates a new advertisement with this Node's VRID and priority.
[ "newAdvertisement", "creates", "a", "new", "advertisement", "with", "this", "Node", "s", "VRID", "and", "priority", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ha/core.go#L149-L156
train
google/seesaw
ha/core.go
Run
func (n *Node) Run() error { go n.receiveAdvertisements() go n.reportStatus() go n.checkConfig() for n.state() != seesaw.HAShutdown { if err := n.runOnce(); err != nil { return err } } return nil }
go
func (n *Node) Run() error { go n.receiveAdvertisements() go n.reportStatus() go n.checkConfig() for n.state() != seesaw.HAShutdown { if err := n.runOnce(); err != nil { return err } } return nil }
[ "func", "(", "n", "*", "Node", ")", "Run", "(", ")", "error", "{", "go", "n", ".", "receiveAdvertisements", "(", ")", "\n", "go", "n", ".", "reportStatus", "(", ")", "\n", "go", "n", ".", "checkConfig", "(", ")", "\n", "for", "n", ".", "state", "(", ")", "!=", "seesaw", ".", "HAShutdown", "{", "if", "err", ":=", "n", ".", "runOnce", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Run sends and receives advertisements, changes this Node's state in response to incoming // advertisements, and periodically notifies the engine of the current state. Run does not return // until Shutdown is called or an unrecoverable error occurs.
[ "Run", "sends", "and", "receives", "advertisements", "changes", "this", "Node", "s", "state", "in", "response", "to", "incoming", "advertisements", "and", "periodically", "notifies", "the", "engine", "of", "the", "current", "state", ".", "Run", "does", "not", "return", "until", "Shutdown", "is", "called", "or", "an", "unrecoverable", "error", "occurs", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ha/core.go#L161-L172
train
google/seesaw
netlink/message.go
registerCallback
func registerCallback(cbArg *callbackArg) uintptr { callbacksLock.Lock() defer callbacksLock.Unlock() cbArg.id = nextCallbackID nextCallbackID++ if _, ok := callbacks[cbArg.id]; ok { panic(fmt.Sprintf("Callback ID %d already in use", cbArg.id)) } callbacks[cbArg.id] = cbArg return cbArg.id }
go
func registerCallback(cbArg *callbackArg) uintptr { callbacksLock.Lock() defer callbacksLock.Unlock() cbArg.id = nextCallbackID nextCallbackID++ if _, ok := callbacks[cbArg.id]; ok { panic(fmt.Sprintf("Callback ID %d already in use", cbArg.id)) } callbacks[cbArg.id] = cbArg return cbArg.id }
[ "func", "registerCallback", "(", "cbArg", "*", "callbackArg", ")", "uintptr", "{", "callbacksLock", ".", "Lock", "(", ")", "\n", "defer", "callbacksLock", ".", "Unlock", "(", ")", "\n", "cbArg", ".", "id", "=", "nextCallbackID", "\n", "nextCallbackID", "++", "\n", "if", "_", ",", "ok", ":=", "callbacks", "[", "cbArg", ".", "id", "]", ";", "ok", "{", "panic", "(", "fmt", ".", "Sprintf", "(", "\"Callback ID %d already in use\"", ",", "cbArg", ".", "id", ")", ")", "\n", "}", "\n", "callbacks", "[", "cbArg", ".", "id", "]", "=", "cbArg", "\n", "return", "cbArg", ".", "id", "\n", "}" ]
// registerCallback registers a callback and returns the allocated callback ID.
[ "registerCallback", "registers", "a", "callback", "and", "returns", "the", "allocated", "callback", "ID", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/netlink/message.go#L77-L87
train
google/seesaw
netlink/message.go
unregisterCallback
func unregisterCallback(cbArg *callbackArg) { callbacksLock.Lock() defer callbacksLock.Unlock() if _, ok := callbacks[cbArg.id]; !ok { panic(fmt.Sprintf("Callback ID %d not registered", cbArg.id)) } delete(callbacks, cbArg.id) }
go
func unregisterCallback(cbArg *callbackArg) { callbacksLock.Lock() defer callbacksLock.Unlock() if _, ok := callbacks[cbArg.id]; !ok { panic(fmt.Sprintf("Callback ID %d not registered", cbArg.id)) } delete(callbacks, cbArg.id) }
[ "func", "unregisterCallback", "(", "cbArg", "*", "callbackArg", ")", "{", "callbacksLock", ".", "Lock", "(", ")", "\n", "defer", "callbacksLock", ".", "Unlock", "(", ")", "\n", "if", "_", ",", "ok", ":=", "callbacks", "[", "cbArg", ".", "id", "]", ";", "!", "ok", "{", "panic", "(", "fmt", ".", "Sprintf", "(", "\"Callback ID %d not registered\"", ",", "cbArg", ".", "id", ")", ")", "\n", "}", "\n", "delete", "(", "callbacks", ",", "cbArg", ".", "id", ")", "\n", "}" ]
// unregisterCallback unregisters a callback.
[ "unregisterCallback", "unregisters", "a", "callback", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/netlink/message.go#L90-L97
train
google/seesaw
netlink/message.go
callback
func callback(nlm *C.struct_nl_msg, nla unsafe.Pointer) C.int { cbID := uintptr(nla) callbacksLock.RLock() cbArg := callbacks[cbID] callbacksLock.RUnlock() if cbArg == nil { panic(fmt.Sprintf("No netlink callback with ID %d", cbID)) } cbMsg := &Message{nlm: nlm} if err := cbArg.fn(cbMsg, cbArg.arg); err != nil { cbArg.err = err return C.NL_STOP } return C.NL_OK }
go
func callback(nlm *C.struct_nl_msg, nla unsafe.Pointer) C.int { cbID := uintptr(nla) callbacksLock.RLock() cbArg := callbacks[cbID] callbacksLock.RUnlock() if cbArg == nil { panic(fmt.Sprintf("No netlink callback with ID %d", cbID)) } cbMsg := &Message{nlm: nlm} if err := cbArg.fn(cbMsg, cbArg.arg); err != nil { cbArg.err = err return C.NL_STOP } return C.NL_OK }
[ "func", "callback", "(", "nlm", "*", "C", ".", "struct_nl_msg", ",", "nla", "unsafe", ".", "Pointer", ")", "C", ".", "int", "{", "cbID", ":=", "uintptr", "(", "nla", ")", "\n", "callbacksLock", ".", "RLock", "(", ")", "\n", "cbArg", ":=", "callbacks", "[", "cbID", "]", "\n", "callbacksLock", ".", "RUnlock", "(", ")", "\n", "if", "cbArg", "==", "nil", "{", "panic", "(", "fmt", ".", "Sprintf", "(", "\"No netlink callback with ID %d\"", ",", "cbID", ")", ")", "\n", "}", "\n", "cbMsg", ":=", "&", "Message", "{", "nlm", ":", "nlm", "}", "\n", "if", "err", ":=", "cbArg", ".", "fn", "(", "cbMsg", ",", "cbArg", ".", "arg", ")", ";", "err", "!=", "nil", "{", "cbArg", ".", "err", "=", "err", "\n", "return", "C", ".", "NL_STOP", "\n", "}", "\n", "return", "C", ".", "NL_OK", "\n", "}" ]
// callback is the Go callback trampoline that is called from the // callbackGateway C function, which in turn gets called from libnl. // //export callback
[ "callback", "is", "the", "Go", "callback", "trampoline", "that", "is", "called", "from", "the", "callbackGateway", "C", "function", "which", "in", "turn", "gets", "called", "from", "libnl", ".", "export", "callback" ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/netlink/message.go#L103-L119
train
google/seesaw
netlink/message.go
NewMessage
func NewMessage(command, family, flags int) (*Message, error) { nlm := C.nlmsg_alloc() if nlm == nil { return nil, errors.New("failed to create netlink message") } C.genlmsg_put(nlm, C.NL_AUTO_PID, C.NL_AUTO_SEQ, C.int(family), 0, C.int(flags), C.uint8_t(command), genlVersion) return &Message{nlm: nlm}, nil }
go
func NewMessage(command, family, flags int) (*Message, error) { nlm := C.nlmsg_alloc() if nlm == nil { return nil, errors.New("failed to create netlink message") } C.genlmsg_put(nlm, C.NL_AUTO_PID, C.NL_AUTO_SEQ, C.int(family), 0, C.int(flags), C.uint8_t(command), genlVersion) return &Message{nlm: nlm}, nil }
[ "func", "NewMessage", "(", "command", ",", "family", ",", "flags", "int", ")", "(", "*", "Message", ",", "error", ")", "{", "nlm", ":=", "C", ".", "nlmsg_alloc", "(", ")", "\n", "if", "nlm", "==", "nil", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"failed to create netlink message\"", ")", "\n", "}", "\n", "C", ".", "genlmsg_put", "(", "nlm", ",", "C", ".", "NL_AUTO_PID", ",", "C", ".", "NL_AUTO_SEQ", ",", "C", ".", "int", "(", "family", ")", ",", "0", ",", "C", ".", "int", "(", "flags", ")", ",", "C", ".", "uint8_t", "(", "command", ")", ",", "genlVersion", ")", "\n", "return", "&", "Message", "{", "nlm", ":", "nlm", "}", ",", "nil", "\n", "}" ]
// NewMessage returns an initialised netlink message.
[ "NewMessage", "returns", "an", "initialised", "netlink", "message", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/netlink/message.go#L135-L142
train
google/seesaw
netlink/message.go
NewMessageFromBytes
func NewMessageFromBytes(nlb []byte) (*Message, error) { nlm := C.nlmsg_alloc_size(C.size_t(len(nlb))) if nlm == nil { return nil, errors.New("failed to create netlink message") } nlh := C.nlmsg_hdr(nlm) copy((*[1 << 20]byte)(unsafe.Pointer(nlh))[:len(nlb)], nlb) return &Message{nlm: nlm}, nil }
go
func NewMessageFromBytes(nlb []byte) (*Message, error) { nlm := C.nlmsg_alloc_size(C.size_t(len(nlb))) if nlm == nil { return nil, errors.New("failed to create netlink message") } nlh := C.nlmsg_hdr(nlm) copy((*[1 << 20]byte)(unsafe.Pointer(nlh))[:len(nlb)], nlb) return &Message{nlm: nlm}, nil }
[ "func", "NewMessageFromBytes", "(", "nlb", "[", "]", "byte", ")", "(", "*", "Message", ",", "error", ")", "{", "nlm", ":=", "C", ".", "nlmsg_alloc_size", "(", "C", ".", "size_t", "(", "len", "(", "nlb", ")", ")", ")", "\n", "if", "nlm", "==", "nil", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"failed to create netlink message\"", ")", "\n", "}", "\n", "nlh", ":=", "C", ".", "nlmsg_hdr", "(", "nlm", ")", "\n", "copy", "(", "(", "*", "[", "1", "<<", "20", "]", "byte", ")", "(", "unsafe", ".", "Pointer", "(", "nlh", ")", ")", "[", ":", "len", "(", "nlb", ")", "]", ",", "nlb", ")", "\n", "return", "&", "Message", "{", "nlm", ":", "nlm", "}", ",", "nil", "\n", "}" ]
// NewMessageFromBytes returns a netlink message that is initialised from the // given byte slice.
[ "NewMessageFromBytes", "returns", "a", "netlink", "message", "that", "is", "initialised", "from", "the", "given", "byte", "slice", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/netlink/message.go#L146-L154
train
google/seesaw
netlink/message.go
Free
func (m *Message) Free() { C.nlmsg_free(m.nlm) m.nlm = nil }
go
func (m *Message) Free() { C.nlmsg_free(m.nlm) m.nlm = nil }
[ "func", "(", "m", "*", "Message", ")", "Free", "(", ")", "{", "C", ".", "nlmsg_free", "(", "m", ".", "nlm", ")", "\n", "m", ".", "nlm", "=", "nil", "\n", "}" ]
// Free frees resources associated with a netlink message.
[ "Free", "frees", "resources", "associated", "with", "a", "netlink", "message", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/netlink/message.go#L157-L160
train
google/seesaw
netlink/message.go
Bytes
func (m *Message) Bytes() ([]byte, error) { if m.nlm == nil { return nil, errors.New("no netlink message") } nlh := C.nlmsg_hdr(m.nlm) nlb := make([]byte, nlh.nlmsg_len) copy(nlb, (*[1 << 20]byte)(unsafe.Pointer(nlh))[:nlh.nlmsg_len]) return nlb, nil }
go
func (m *Message) Bytes() ([]byte, error) { if m.nlm == nil { return nil, errors.New("no netlink message") } nlh := C.nlmsg_hdr(m.nlm) nlb := make([]byte, nlh.nlmsg_len) copy(nlb, (*[1 << 20]byte)(unsafe.Pointer(nlh))[:nlh.nlmsg_len]) return nlb, nil }
[ "func", "(", "m", "*", "Message", ")", "Bytes", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "m", ".", "nlm", "==", "nil", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"no netlink message\"", ")", "\n", "}", "\n", "nlh", ":=", "C", ".", "nlmsg_hdr", "(", "m", ".", "nlm", ")", "\n", "nlb", ":=", "make", "(", "[", "]", "byte", ",", "nlh", ".", "nlmsg_len", ")", "\n", "copy", "(", "nlb", ",", "(", "*", "[", "1", "<<", "20", "]", "byte", ")", "(", "unsafe", ".", "Pointer", "(", "nlh", ")", ")", "[", ":", "nlh", ".", "nlmsg_len", "]", ")", "\n", "return", "nlb", ",", "nil", "\n", "}" ]
// Bytes returns the byte slice representation of a netlink message.
[ "Bytes", "returns", "the", "byte", "slice", "representation", "of", "a", "netlink", "message", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/netlink/message.go#L163-L171
train
google/seesaw
netlink/message.go
Unmarshal
func (m *Message) Unmarshal(v interface{}) error { val := reflect.Indirect(reflect.ValueOf(v)) if val.Kind() != reflect.Struct || !val.CanSet() { return fmt.Errorf("%v is not a pointer to a struct", reflect.TypeOf(v)) } maxAttrID, err := structMaxAttrID(val) if err != nil { return err } attrs, err := parseMessage(m.nlm, maxAttrID) if err != nil { return err } return unmarshal(val, "", nil, attrs) }
go
func (m *Message) Unmarshal(v interface{}) error { val := reflect.Indirect(reflect.ValueOf(v)) if val.Kind() != reflect.Struct || !val.CanSet() { return fmt.Errorf("%v is not a pointer to a struct", reflect.TypeOf(v)) } maxAttrID, err := structMaxAttrID(val) if err != nil { return err } attrs, err := parseMessage(m.nlm, maxAttrID) if err != nil { return err } return unmarshal(val, "", nil, attrs) }
[ "func", "(", "m", "*", "Message", ")", "Unmarshal", "(", "v", "interface", "{", "}", ")", "error", "{", "val", ":=", "reflect", ".", "Indirect", "(", "reflect", ".", "ValueOf", "(", "v", ")", ")", "\n", "if", "val", ".", "Kind", "(", ")", "!=", "reflect", ".", "Struct", "||", "!", "val", ".", "CanSet", "(", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"%v is not a pointer to a struct\"", ",", "reflect", ".", "TypeOf", "(", "v", ")", ")", "\n", "}", "\n", "maxAttrID", ",", "err", ":=", "structMaxAttrID", "(", "val", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "attrs", ",", "err", ":=", "parseMessage", "(", "m", ".", "nlm", ",", "maxAttrID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "unmarshal", "(", "val", ",", "\"\"", ",", "nil", ",", "attrs", ")", "\n", "}" ]
// Unmarshal parses the netlink message and fills the struct referenced by the // given pointer. The supported data types and netlink encodings are the same // as for Marshal.
[ "Unmarshal", "parses", "the", "netlink", "message", "and", "fills", "the", "struct", "referenced", "by", "the", "given", "pointer", ".", "The", "supported", "data", "types", "and", "netlink", "encodings", "are", "the", "same", "as", "for", "Marshal", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/netlink/message.go#L209-L223
train
google/seesaw
netlink/message.go
SendCallback
func (m *Message) SendCallback(fn CallbackFunc, arg interface{}) error { s, err := newSocket() if err != nil { return err } defer s.free() if errno := C.genl_connect(s.nls); errno != 0 { return &Error{errno, "failed to connect to netlink"} } defer C.nl_close(s.nls) cbArg := &callbackArg{fn: fn, arg: arg} cbID := registerCallback(cbArg) defer unregisterCallback(cbArg) if errno := C._nl_socket_modify_cb(s.nls, C.NL_CB_VALID, C.NL_CB_CUSTOM, (C.nl_recvmsg_msg_cb_t)(unsafe.Pointer(C.callbackGateway)), C.uintptr_t(cbID)); errno != 0 { return &Error{errno, "failed to modify callback"} } // nl_send_auto_complete returns number of bytes sent or a negative // errno on failure. if errno := C.nl_send_auto_complete(s.nls, m.nlm); errno < 0 { return &Error{errno, "failed to send netlink message"} } if errno := C.nl_recvmsgs_default(s.nls); errno != 0 { return &Error{errno, "failed to receive messages"} } return nil }
go
func (m *Message) SendCallback(fn CallbackFunc, arg interface{}) error { s, err := newSocket() if err != nil { return err } defer s.free() if errno := C.genl_connect(s.nls); errno != 0 { return &Error{errno, "failed to connect to netlink"} } defer C.nl_close(s.nls) cbArg := &callbackArg{fn: fn, arg: arg} cbID := registerCallback(cbArg) defer unregisterCallback(cbArg) if errno := C._nl_socket_modify_cb(s.nls, C.NL_CB_VALID, C.NL_CB_CUSTOM, (C.nl_recvmsg_msg_cb_t)(unsafe.Pointer(C.callbackGateway)), C.uintptr_t(cbID)); errno != 0 { return &Error{errno, "failed to modify callback"} } // nl_send_auto_complete returns number of bytes sent or a negative // errno on failure. if errno := C.nl_send_auto_complete(s.nls, m.nlm); errno < 0 { return &Error{errno, "failed to send netlink message"} } if errno := C.nl_recvmsgs_default(s.nls); errno != 0 { return &Error{errno, "failed to receive messages"} } return nil }
[ "func", "(", "m", "*", "Message", ")", "SendCallback", "(", "fn", "CallbackFunc", ",", "arg", "interface", "{", "}", ")", "error", "{", "s", ",", "err", ":=", "newSocket", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "s", ".", "free", "(", ")", "\n", "if", "errno", ":=", "C", ".", "genl_connect", "(", "s", ".", "nls", ")", ";", "errno", "!=", "0", "{", "return", "&", "Error", "{", "errno", ",", "\"failed to connect to netlink\"", "}", "\n", "}", "\n", "defer", "C", ".", "nl_close", "(", "s", ".", "nls", ")", "\n", "cbArg", ":=", "&", "callbackArg", "{", "fn", ":", "fn", ",", "arg", ":", "arg", "}", "\n", "cbID", ":=", "registerCallback", "(", "cbArg", ")", "\n", "defer", "unregisterCallback", "(", "cbArg", ")", "\n", "if", "errno", ":=", "C", ".", "_nl_socket_modify_cb", "(", "s", ".", "nls", ",", "C", ".", "NL_CB_VALID", ",", "C", ".", "NL_CB_CUSTOM", ",", "(", "C", ".", "nl_recvmsg_msg_cb_t", ")", "(", "unsafe", ".", "Pointer", "(", "C", ".", "callbackGateway", ")", ")", ",", "C", ".", "uintptr_t", "(", "cbID", ")", ")", ";", "errno", "!=", "0", "{", "return", "&", "Error", "{", "errno", ",", "\"failed to modify callback\"", "}", "\n", "}", "\n", "if", "errno", ":=", "C", ".", "nl_send_auto_complete", "(", "s", ".", "nls", ",", "m", ".", "nlm", ")", ";", "errno", "<", "0", "{", "return", "&", "Error", "{", "errno", ",", "\"failed to send netlink message\"", "}", "\n", "}", "\n", "if", "errno", ":=", "C", ".", "nl_recvmsgs_default", "(", "s", ".", "nls", ")", ";", "errno", "!=", "0", "{", "return", "&", "Error", "{", "errno", ",", "\"failed to receive messages\"", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// SendCallback sends the netlink message. The specified callback function // will be called for each message that is received in response.
[ "SendCallback", "sends", "the", "netlink", "message", ".", "The", "specified", "callback", "function", "will", "be", "called", "for", "each", "message", "that", "is", "received", "in", "response", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/netlink/message.go#L232-L260
train