repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
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",
"(",
")",
"{",
"// TODO(jsing): Make this default to IPv6, if configured.",
"addr",
":=",
"&",
"net",
".",
"TCPAddr",
"{",
"IP",
":",
"e",
".",
"config",
".",
"Node",
".",
"IPv4Addr",
",",
"Port",
":",
"e",
".",
"config",
".",
"SyncPort",
",",
"}",
"\n",
"ln",
",",
"err",
":=",
"net",
".",
"ListenTCP",
"(",
"\"",
"\"",
",",
"addr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"go",
"e",
".",
"syncServer",
".",
"serve",
"(",
"ln",
")",
"\n\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",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"e",
".",
"ncc",
".",
"Close",
"(",
")",
"\n\n",
"if",
"e",
".",
"config",
".",
"AnycastEnabled",
"{",
"if",
"err",
":=",
"e",
".",
"ncc",
".",
"BGPWithdrawAll",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"err",
":=",
"e",
".",
"ncc",
".",
"IPVSFlush",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\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\n",
"if",
"err",
":=",
"e",
".",
"lbInterface",
".",
"Init",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\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",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"e",
".",
"ncc",
".",
"Close",
"(",
")",
"\n\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",
"(",
"\"",
"\"",
",",
"vip",
",",
"err",
")",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"vip",
")",
"\n",
"if",
"err",
":=",
"e",
".",
"ncc",
".",
"BGPAdvertiseVIP",
"(",
"vip",
".",
"IP",
".",
"IP",
"(",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"e",
".",
"config",
".",
"ClusterVIP",
".",
"IPv4Addr",
")",
"\n",
"announced",
"=",
"false",
"\n",
"}",
"\n",
"continue",
"\n",
"}",
"\n",
"if",
"!",
"announced",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"e",
".",
"config",
".",
"ClusterVIP",
".",
"IPv4Addr",
",",
"e",
".",
"config",
".",
"LBInterface",
",",
"e",
".",
"config",
".",
"GratuitousARPInterval",
")",
"\n",
"announced",
"=",
"true",
"\n",
"}",
"\n",
"if",
"err",
":=",
"e",
".",
"ncc",
".",
"Dial",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"e",
".",
"ncc",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
":=",
"e",
".",
"ncc",
".",
"ARPSendGratuitous",
"(",
"e",
".",
"config",
".",
"LBInterface",
",",
"e",
".",
"config",
".",
"ClusterVIP",
".",
"IPv4Addr",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\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\n",
"// Delete vservers that no longer exist in the new configuration.",
"for",
"name",
",",
"vserver",
":=",
"range",
"e",
".",
"vservers",
"{",
"if",
"cluster",
".",
"Vservers",
"[",
"name",
"]",
"==",
"nil",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"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\n",
"// Spawn new vservers and provide current configurations.",
"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\n",
"add",
":=",
"make",
"(",
"[",
"]",
"*",
"seesaw",
".",
"VLAN",
",",
"0",
")",
"\n",
"remove",
":=",
"make",
"(",
"[",
"]",
"*",
"seesaw",
".",
"VLAN",
",",
"0",
")",
"\n\n",
"e",
".",
"vlanLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"e",
".",
"vlanLock",
".",
"Unlock",
"(",
")",
"\n\n",
"for",
"key",
",",
"vlan",
":=",
"range",
"e",
".",
"vlans",
"{",
"if",
"cluster",
".",
"VLANs",
"[",
"key",
"]",
"==",
"nil",
"{",
"remove",
"=",
"append",
"(",
"remove",
",",
"vlan",
")",
"\n",
"}",
"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",
")",
"\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\n",
"if",
"err",
":=",
"e",
".",
"ncc",
".",
"Dial",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"e",
".",
"ncc",
".",
"Close",
"(",
")",
"\n\n",
"for",
"_",
",",
"vlan",
":=",
"range",
"remove",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"vlan",
")",
"\n",
"if",
"err",
":=",
"e",
".",
"lbInterface",
".",
"DeleteVLAN",
"(",
"vlan",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"vlan",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"vlan",
":=",
"range",
"add",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"vlan",
")",
"\n",
"if",
"err",
":=",
"e",
".",
"lbInterface",
".",
"AddVLAN",
"(",
"vlan",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"vlan",
",",
"err",
")",
"\n",
"}",
"\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",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"e",
".",
"ncc",
".",
"Close",
"(",
")",
"\n\n",
"e",
".",
"vlanLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"e",
".",
"vlanLock",
".",
"Unlock",
"(",
")",
"\n\n",
"for",
"k",
",",
"v",
":=",
"range",
"e",
".",
"vlans",
"{",
"if",
"err",
":=",
"e",
".",
"lbInterface",
".",
"DeleteVLAN",
"(",
"v",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"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",
")",
"{",
"// 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",
")",
"\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",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"e",
".",
"ncc",
".",
"Close",
"(",
")",
"\n\n",
"e",
".",
"syncClient",
".",
"disable",
"(",
")",
"\n",
"e",
".",
"hcManager",
".",
"enable",
"(",
")",
"\n",
"e",
".",
"notifier",
".",
"SetSource",
"(",
"config",
".",
"SourceServer",
")",
"\n\n",
"if",
"err",
":=",
"e",
".",
"lbInterface",
".",
"Up",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"e",
".",
"ncc",
".",
"Close",
"(",
")",
"\n\n",
"e",
".",
"syncClient",
".",
"enable",
"(",
")",
"\n",
"e",
".",
"hcManager",
".",
"disable",
"(",
")",
"\n",
"e",
".",
"notifier",
".",
"SetSource",
"(",
"config",
".",
"SourcePeer",
")",
"\n\n",
"if",
"err",
":=",
"e",
".",
"lbInterface",
".",
"Down",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// 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",
"(",
")",
"\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",
"(",
"\"",
"\"",
")",
"\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",
"(",
"\"",
"\"",
")",
"\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",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"authCtx",
",",
"err",
":=",
"e",
".",
"authenticate",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"seesawConn",
",",
"err",
":=",
"conn",
".",
"NewSeesawIPC",
"(",
"authCtx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"seesawConn",
".",
"Dial",
"(",
"e",
".",
"cfg",
".",
"EngineSocket",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\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",
":",
"// Ctrl-A",
"return",
"line",
",",
"0",
",",
"true",
"\n",
"case",
"0x03",
":",
"// Ctrl-C",
"exit",
"(",
")",
"\n",
"case",
"0x05",
":",
"// Ctrl-E",
"return",
"line",
",",
"len",
"(",
"line",
")",
",",
"true",
"\n",
"case",
"0x09",
":",
"// Ctrl-I (Tab)",
"_",
",",
"_",
",",
"chain",
",",
"args",
":=",
"cli",
".",
"FindCommand",
"(",
"string",
"(",
"line",
")",
")",
"\n",
"line",
":=",
"commandChain",
"(",
"chain",
",",
"args",
")",
"\n",
"return",
"line",
",",
"len",
"(",
"line",
")",
",",
"true",
"\n",
"case",
"0x15",
":",
"// Ctrl-U",
"return",
"\"",
"\"",
",",
"0",
",",
"true",
"\n",
"case",
"0x1a",
":",
"// Ctrl-Z",
"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",
"if",
"subcmds",
"!=",
"nil",
"{",
"for",
"_",
",",
"c",
":=",
"range",
"*",
"subcmds",
"{",
"term",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"\"",
"\"",
"+",
"c",
".",
"Command",
")",
")",
"\n",
"term",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"\"",
"\\n",
"\"",
")",
")",
"\n",
"}",
"\n",
"}",
"else",
"if",
"cmd",
"==",
"nil",
"{",
"term",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"\"",
"\\n",
"\"",
")",
")",
"\n",
"}",
"\n\n",
"line",
":=",
"commandChain",
"(",
"chain",
",",
"args",
")",
"\n",
"return",
"line",
",",
"len",
"(",
"line",
")",
",",
"true",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"0",
",",
"false",
"\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",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\\n",
"\\n",
"\"",
",",
"status",
".",
"Version",
")",
"\n\n",
"u",
",",
"err",
":=",
"user",
".",
"Current",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"ha",
",",
"err",
":=",
"seesawConn",
".",
"HAStatus",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"ha",
".",
"State",
"!=",
"seesaw",
".",
"HAMaster",
"{",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"prompt",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"u",
".",
"Username",
",",
"status",
".",
"Site",
")",
"\n\n",
"// Setup signal handler before we switch to a raw terminal.",
"sigc",
":=",
"make",
"(",
"chan",
"os",
".",
"Signal",
",",
"3",
")",
"\n",
"signal",
".",
"Notify",
"(",
"sigc",
",",
"syscall",
".",
"SIGINT",
",",
"syscall",
".",
"SIGQUIT",
",",
"syscall",
".",
"SIGTERM",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"<-",
"sigc",
"\n",
"exit",
"(",
")",
"\n",
"}",
"(",
")",
"\n\n",
"terminalInit",
"(",
")",
"\n\n",
"for",
"{",
"cmdline",
",",
"err",
":=",
"term",
".",
"ReadLine",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"break",
"\n",
"}",
"\n",
"cmdline",
"=",
"strings",
".",
"TrimSpace",
"(",
"cmdline",
")",
"\n",
"if",
"cmdline",
"==",
"\"",
"\"",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"err",
":=",
"seesawCLI",
".",
"Execute",
"(",
"cmdline",
")",
";",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Println",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\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\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\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\n",
"// 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",
"\n",
"}",
"else",
"{",
"svc",
".",
"Address",
"=",
"net",
".",
"IPv6zero",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"ipvsSvc",
".",
"Stats",
"!=",
"nil",
"{",
"*",
"svc",
".",
"Statistics",
"=",
"*",
"ipvsSvc",
".",
"Stats",
"\n",
"}",
"\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",
")",
",",
"// TODO(jsing): uint32?",
"Flags",
":",
"ipvsDst",
".",
"Flags",
",",
"LowerThreshold",
":",
"ipvsDst",
".",
"LowerThreshold",
",",
"UpperThreshold",
":",
"ipvsDst",
".",
"UpperThreshold",
",",
"Statistics",
":",
"&",
"DestinationStats",
"{",
"}",
",",
"}",
"\n\n",
"if",
"ipvsDst",
".",
"Stats",
"!=",
"nil",
"{",
"*",
"dst",
".",
"Statistics",
"=",
"*",
"ipvsDst",
".",
"Stats",
"\n",
"}",
"\n\n",
"dst",
".",
"Statistics",
".",
"ActiveConns",
"=",
"ipvsDst",
".",
"ActiveConns",
"\n",
"dst",
".",
"Statistics",
".",
"InactiveConns",
"=",
"ipvsDst",
".",
"InactiveConns",
"\n",
"dst",
".",
"Statistics",
".",
"PersistConns",
"=",
"ipvsDst",
".",
"PersistConns",
"\n\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",
"(",
"\"",
"\"",
",",
"svc",
".",
"FirewallMark",
",",
"svc",
".",
"Scheduler",
")",
"\n",
"case",
"svc",
".",
"Address",
".",
"To4",
"(",
")",
"==",
"nil",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"svc",
".",
"Protocol",
",",
"svc",
".",
"Address",
",",
"svc",
".",
"Port",
",",
"svc",
".",
"Scheduler",
")",
"\n",
"default",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"addr",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"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\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\n",
"ic",
":=",
"&",
"ipvsCommand",
"{",
"Service",
":",
"newIPVSService",
"(",
"svc",
")",
"}",
"\n",
"if",
"err",
":=",
"msg",
".",
"Marshal",
"(",
"ic",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\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",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"ic",
".",
"Destination",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\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\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\n",
"if",
"svc",
"!=",
"nil",
"{",
"ic",
":=",
"&",
"ipvsCommand",
"{",
"Service",
":",
"newIPVSService",
"(",
"svc",
")",
"}",
"\n",
"if",
"err",
":=",
"msg",
".",
"Marshal",
"(",
"ic",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\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",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"ic",
".",
"Service",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\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\n",
"for",
"_",
",",
"svc",
":=",
"range",
"svcs",
"{",
"dsts",
",",
"err",
":=",
"destinations",
"(",
"svc",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"svc",
".",
"Destinations",
"=",
"dsts",
"\n",
"}",
"\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",
"(",
"\"",
"\"",
")",
"\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",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"e",
".",
"Socket",
",",
"engineTimeout",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"engineConn",
".",
"SetDeadline",
"(",
"time",
".",
"Now",
"(",
")",
".",
"Add",
"(",
"engineTimeout",
")",
")",
"\n",
"engine",
":=",
"rpc",
".",
"NewClient",
"(",
"engineConn",
")",
"\n",
"defer",
"engine",
".",
"Close",
"(",
")",
"\n\n",
"var",
"config",
"seesaw",
".",
"HAConfig",
"\n",
"ctx",
":=",
"ipc",
".",
"NewTrustedContext",
"(",
"seesaw",
".",
"SCHA",
")",
"\n",
"if",
"err",
":=",
"engine",
".",
"Call",
"(",
"\"",
"\"",
",",
"ctx",
",",
"&",
"config",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"e",
".",
"Socket",
",",
"engineTimeout",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"engineConn",
".",
"SetDeadline",
"(",
"time",
".",
"Now",
"(",
")",
".",
"Add",
"(",
"engineTimeout",
")",
")",
"\n",
"engine",
":=",
"rpc",
".",
"NewClient",
"(",
"engineConn",
")",
"\n",
"defer",
"engine",
".",
"Close",
"(",
")",
"\n\n",
"var",
"failover",
"bool",
"\n",
"ctx",
":=",
"ipc",
".",
"NewTrustedContext",
"(",
"seesaw",
".",
"SCHA",
")",
"\n",
"if",
"err",
":=",
"engine",
".",
"Call",
"(",
"\"",
"\"",
",",
"&",
"ipc",
".",
"HAStatus",
"{",
"ctx",
",",
"status",
"}",
",",
"&",
"failover",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"socket",
",",
"5",
"*",
"time",
".",
"Second",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"c",
".",
"Close",
"(",
")",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"socket",
")",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"os",
".",
"MkdirAll",
"(",
"serverRunDir",
",",
"0700",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"os",
".",
"Chown",
"(",
"serverRunDir",
",",
"owner",
",",
"group",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"os",
".",
"Chmod",
"(",
"serverRunDir",
",",
"0770",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
")",
"\n",
"for",
"{",
"conn",
",",
"err",
":=",
"ln",
".",
"Accept",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"ne",
",",
"ok",
":=",
"err",
".",
"(",
"net",
".",
"Error",
")",
";",
"ok",
"&&",
"ne",
".",
"Temporary",
"(",
")",
"{",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"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",
"\"",
"\"",
"\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\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\n",
"files",
",",
"err",
":=",
"d",
".",
"Readdir",
"(",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"sort",
".",
"Sort",
"(",
"sort",
".",
"Reverse",
"(",
"byModTime",
"(",
"files",
")",
")",
")",
"\n\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\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",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"ln",
",",
"err",
":=",
"net",
".",
"Listen",
"(",
"\"",
"\"",
",",
"n",
".",
"nccSocket",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"ln",
".",
"Close",
"(",
")",
"\n",
"defer",
"os",
".",
"Remove",
"(",
"n",
".",
"nccSocket",
")",
"\n\n",
"seesawNCC",
":=",
"rpc",
".",
"NewServer",
"(",
")",
"\n",
"seesawNCC",
".",
"Register",
"(",
"&",
"SeesawNCC",
"{",
"}",
")",
"\n",
"go",
"server",
".",
"RPCAccept",
"(",
"ln",
",",
"seesawNCC",
")",
"\n\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",
"(",
"\"",
"\"",
",",
"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",
")",
",",
"// AdvertInt is in centiseconds",
"}",
"\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\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",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"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\n",
"if",
"cbArg",
"==",
"nil",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"cbID",
")",
")",
"\n",
"}",
"\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",
"(",
"\"",
"\"",
")",
"\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",
"(",
"\"",
"\"",
")",
"\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",
"(",
"\"",
"\"",
")",
"\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",
"(",
"\"",
"\"",
",",
"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\n",
"if",
"errno",
":=",
"C",
".",
"genl_connect",
"(",
"s",
".",
"nls",
")",
";",
"errno",
"!=",
"0",
"{",
"return",
"&",
"Error",
"{",
"errno",
",",
"\"",
"\"",
"}",
"\n",
"}",
"\n",
"defer",
"C",
".",
"nl_close",
"(",
"s",
".",
"nls",
")",
"\n\n",
"cbArg",
":=",
"&",
"callbackArg",
"{",
"fn",
":",
"fn",
",",
"arg",
":",
"arg",
"}",
"\n",
"cbID",
":=",
"registerCallback",
"(",
"cbArg",
")",
"\n",
"defer",
"unregisterCallback",
"(",
"cbArg",
")",
"\n\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",
",",
"\"",
"\"",
"}",
"\n",
"}",
"\n",
"// 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",
",",
"\"",
"\"",
"}",
"\n",
"}",
"\n",
"if",
"errno",
":=",
"C",
".",
"nl_recvmsgs_default",
"(",
"s",
".",
"nls",
")",
";",
"errno",
"!=",
"0",
"{",
"return",
"&",
"Error",
"{",
"errno",
",",
"\"",
"\"",
"}",
"\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 |
google/seesaw | netlink/message.go | SendMessage | func SendMessage(command, family, flags int) error {
return SendMessageCallback(command, family, flags, callbackDefault, nil)
} | go | func SendMessage(command, family, flags int) error {
return SendMessageCallback(command, family, flags, callbackDefault, nil)
} | [
"func",
"SendMessage",
"(",
"command",
",",
"family",
",",
"flags",
"int",
")",
"error",
"{",
"return",
"SendMessageCallback",
"(",
"command",
",",
"family",
",",
"flags",
",",
"callbackDefault",
",",
"nil",
")",
"\n",
"}"
] | // SendMessage creates and sends a netlink message. | [
"SendMessage",
"creates",
"and",
"sends",
"a",
"netlink",
"message",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/netlink/message.go#L263-L265 | train |
google/seesaw | netlink/message.go | SendMessageCallback | func SendMessageCallback(command, family, flags int, cb CallbackFunc, arg interface{}) error {
msg, err := NewMessage(command, family, flags)
if err != nil {
return err
}
defer msg.Free()
return msg.SendCallback(cb, arg)
} | go | func SendMessageCallback(command, family, flags int, cb CallbackFunc, arg interface{}) error {
msg, err := NewMessage(command, family, flags)
if err != nil {
return err
}
defer msg.Free()
return msg.SendCallback(cb, arg)
} | [
"func",
"SendMessageCallback",
"(",
"command",
",",
"family",
",",
"flags",
"int",
",",
"cb",
"CallbackFunc",
",",
"arg",
"interface",
"{",
"}",
")",
"error",
"{",
"msg",
",",
"err",
":=",
"NewMessage",
"(",
"command",
",",
"family",
",",
"flags",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"msg",
".",
"Free",
"(",
")",
"\n\n",
"return",
"msg",
".",
"SendCallback",
"(",
"cb",
",",
"arg",
")",
"\n",
"}"
] | // SendMessageCallback creates and sends a netlink message. The specified
// callback function will be called for each message that is received in
// response. | [
"SendMessageCallback",
"creates",
"and",
"sends",
"a",
"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#L270-L278 | train |
google/seesaw | netlink/message.go | SendMessageMarshalled | func SendMessageMarshalled(command, family, flags int, v interface{}) error {
msg, err := NewMessage(command, family, flags)
if err != nil {
return err
}
defer msg.Free()
if err := msg.Marshal(v); err != nil {
return err
}
return msg.Send()
} | go | func SendMessageMarshalled(command, family, flags int, v interface{}) error {
msg, err := NewMessage(command, family, flags)
if err != nil {
return err
}
defer msg.Free()
if err := msg.Marshal(v); err != nil {
return err
}
return msg.Send()
} | [
"func",
"SendMessageMarshalled",
"(",
"command",
",",
"family",
",",
"flags",
"int",
",",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"msg",
",",
"err",
":=",
"NewMessage",
"(",
"command",
",",
"family",
",",
"flags",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"msg",
".",
"Free",
"(",
")",
"\n\n",
"if",
"err",
":=",
"msg",
".",
"Marshal",
"(",
"v",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"msg",
".",
"Send",
"(",
")",
"\n",
"}"
] | // SendMessageMarshalled creates a netlink message and marshals the given
// struct into the message, before sending it. | [
"SendMessageMarshalled",
"creates",
"a",
"netlink",
"message",
"and",
"marshals",
"the",
"given",
"struct",
"into",
"the",
"message",
"before",
"sending",
"it",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/netlink/message.go#L282-L293 | train |
google/seesaw | netlink/message.go | SendMessageUnmarshal | func SendMessageUnmarshal(command, family, flags int, v interface{}) error {
return SendMessageCallback(command, family, flags, callbackUnmarshal, v)
} | go | func SendMessageUnmarshal(command, family, flags int, v interface{}) error {
return SendMessageCallback(command, family, flags, callbackUnmarshal, v)
} | [
"func",
"SendMessageUnmarshal",
"(",
"command",
",",
"family",
",",
"flags",
"int",
",",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"SendMessageCallback",
"(",
"command",
",",
"family",
",",
"flags",
",",
"callbackUnmarshal",
",",
"v",
")",
"\n",
"}"
] | // SendMessageUnmarshal creates and sends a netlink message. All messages
// received in response will be unmarshalled into the given struct. | [
"SendMessageUnmarshal",
"creates",
"and",
"sends",
"a",
"netlink",
"message",
".",
"All",
"messages",
"received",
"in",
"response",
"will",
"be",
"unmarshalled",
"into",
"the",
"given",
"struct",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/netlink/message.go#L297-L299 | train |
google/seesaw | binaries/seesaw_ha/main.go | config | func config(e ha.Engine) *seesaw.HAConfig {
for {
c, err := e.HAConfig()
switch {
case err != nil:
log.Errorf("config: Failed to retrieve HAConfig: %v", err)
case !c.Enabled:
log.Infof("config: HA peering is currently disabled for this node")
default:
return c
}
time.Sleep(*initConfigRetryDelay)
}
} | go | func config(e ha.Engine) *seesaw.HAConfig {
for {
c, err := e.HAConfig()
switch {
case err != nil:
log.Errorf("config: Failed to retrieve HAConfig: %v", err)
case !c.Enabled:
log.Infof("config: HA peering is currently disabled for this node")
default:
return c
}
time.Sleep(*initConfigRetryDelay)
}
} | [
"func",
"config",
"(",
"e",
"ha",
".",
"Engine",
")",
"*",
"seesaw",
".",
"HAConfig",
"{",
"for",
"{",
"c",
",",
"err",
":=",
"e",
".",
"HAConfig",
"(",
")",
"\n",
"switch",
"{",
"case",
"err",
"!=",
"nil",
":",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n\n",
"case",
"!",
"c",
".",
"Enabled",
":",
"log",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n\n",
"default",
":",
"return",
"c",
"\n",
"}",
"\n",
"time",
".",
"Sleep",
"(",
"*",
"initConfigRetryDelay",
")",
"\n",
"}",
"\n",
"}"
] | // config reads the HAConfig from the engine. It does not return until it
// successfully retrieves an HAConfig that has HA peering enabled. | [
"config",
"reads",
"the",
"HAConfig",
"from",
"the",
"engine",
".",
"It",
"does",
"not",
"return",
"until",
"it",
"successfully",
"retrieves",
"an",
"HAConfig",
"that",
"has",
"HA",
"peering",
"enabled",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/binaries/seesaw_ha/main.go#L81-L96 | train |
google/seesaw | engine/bgp.go | newBGPManager | func newBGPManager(engine *Engine, interval time.Duration) *bgpManager {
return &bgpManager{engine: engine, updateInterval: interval}
} | go | func newBGPManager(engine *Engine, interval time.Duration) *bgpManager {
return &bgpManager{engine: engine, updateInterval: interval}
} | [
"func",
"newBGPManager",
"(",
"engine",
"*",
"Engine",
",",
"interval",
"time",
".",
"Duration",
")",
"*",
"bgpManager",
"{",
"return",
"&",
"bgpManager",
"{",
"engine",
":",
"engine",
",",
"updateInterval",
":",
"interval",
"}",
"\n",
"}"
] | // newBGPManager returns an initialised bgpManager struct. | [
"newBGPManager",
"returns",
"an",
"initialised",
"bgpManager",
"struct",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/bgp.go#L41-L43 | train |
google/seesaw | engine/bgp.go | run | func (b *bgpManager) run() {
ticker := time.NewTicker(b.updateInterval)
for {
log.V(1).Infof("Updating BGP state and statistics...")
b.update()
<-ticker.C
}
} | go | func (b *bgpManager) run() {
ticker := time.NewTicker(b.updateInterval)
for {
log.V(1).Infof("Updating BGP state and statistics...")
b.update()
<-ticker.C
}
} | [
"func",
"(",
"b",
"*",
"bgpManager",
")",
"run",
"(",
")",
"{",
"ticker",
":=",
"time",
".",
"NewTicker",
"(",
"b",
".",
"updateInterval",
")",
"\n",
"for",
"{",
"log",
".",
"V",
"(",
"1",
")",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"b",
".",
"update",
"(",
")",
"\n",
"<-",
"ticker",
".",
"C",
"\n",
"}",
"\n",
"}"
] | // run runs the BGP configuration manager. | [
"run",
"runs",
"the",
"BGP",
"configuration",
"manager",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/bgp.go#L46-L53 | train |
google/seesaw | engine/bgp.go | update | func (b *bgpManager) update() {
ncc := b.engine.ncc
if err := ncc.Dial(); err != nil {
log.Warningf("BGP manager failed to connect to NCC: %v", err)
return
}
defer ncc.Close()
neighbors, err := ncc.BGPNeighbors()
if err != nil {
log.Warningf("Failed to get BGP neighbors: %v", err)
return
}
b.lock.Lock()
b.neighbors = neighbors
b.lock.Unlock()
} | go | func (b *bgpManager) update() {
ncc := b.engine.ncc
if err := ncc.Dial(); err != nil {
log.Warningf("BGP manager failed to connect to NCC: %v", err)
return
}
defer ncc.Close()
neighbors, err := ncc.BGPNeighbors()
if err != nil {
log.Warningf("Failed to get BGP neighbors: %v", err)
return
}
b.lock.Lock()
b.neighbors = neighbors
b.lock.Unlock()
} | [
"func",
"(",
"b",
"*",
"bgpManager",
")",
"update",
"(",
")",
"{",
"ncc",
":=",
"b",
".",
"engine",
".",
"ncc",
"\n",
"if",
"err",
":=",
"ncc",
".",
"Dial",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"defer",
"ncc",
".",
"Close",
"(",
")",
"\n\n",
"neighbors",
",",
"err",
":=",
"ncc",
".",
"BGPNeighbors",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"b",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"b",
".",
"neighbors",
"=",
"neighbors",
"\n",
"b",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"}"
] | // update updates BGP related state and statistics from the BGP daemon. | [
"update",
"updates",
"BGP",
"related",
"state",
"and",
"statistics",
"from",
"the",
"BGP",
"daemon",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/bgp.go#L56-L72 | train |
google/seesaw | healthcheck/http.go | NewHTTPChecker | func NewHTTPChecker(ip net.IP, port int) *HTTPChecker {
return &HTTPChecker{
Target: Target{
IP: ip,
Port: port,
Proto: seesaw.IPProtoTCP,
},
Secure: false,
TLSVerify: true,
Method: "GET",
Proxy: false,
Request: "/",
Response: "",
ResponseCode: 200,
}
} | go | func NewHTTPChecker(ip net.IP, port int) *HTTPChecker {
return &HTTPChecker{
Target: Target{
IP: ip,
Port: port,
Proto: seesaw.IPProtoTCP,
},
Secure: false,
TLSVerify: true,
Method: "GET",
Proxy: false,
Request: "/",
Response: "",
ResponseCode: 200,
}
} | [
"func",
"NewHTTPChecker",
"(",
"ip",
"net",
".",
"IP",
",",
"port",
"int",
")",
"*",
"HTTPChecker",
"{",
"return",
"&",
"HTTPChecker",
"{",
"Target",
":",
"Target",
"{",
"IP",
":",
"ip",
",",
"Port",
":",
"port",
",",
"Proto",
":",
"seesaw",
".",
"IPProtoTCP",
",",
"}",
",",
"Secure",
":",
"false",
",",
"TLSVerify",
":",
"true",
",",
"Method",
":",
"\"",
"\"",
",",
"Proxy",
":",
"false",
",",
"Request",
":",
"\"",
"\"",
",",
"Response",
":",
"\"",
"\"",
",",
"ResponseCode",
":",
"200",
",",
"}",
"\n",
"}"
] | // NewHTTPChecker returns an initialised HTTPChecker. | [
"NewHTTPChecker",
"returns",
"an",
"initialised",
"HTTPChecker",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/http.go#L52-L67 | train |
google/seesaw | healthcheck/http.go | String | func (hc *HTTPChecker) String() string {
attr := []string{fmt.Sprintf("code %d", hc.ResponseCode)}
if hc.Proxy {
attr = append(attr, "proxy")
}
if hc.Secure {
attr = append(attr, "secure")
if hc.TLSVerify {
attr = append(attr, "verify")
}
}
s := strings.Join(attr, "; ")
return fmt.Sprintf("HTTP %s %s [%s] %s", hc.Method, hc.Request, s, hc.Target)
} | go | func (hc *HTTPChecker) String() string {
attr := []string{fmt.Sprintf("code %d", hc.ResponseCode)}
if hc.Proxy {
attr = append(attr, "proxy")
}
if hc.Secure {
attr = append(attr, "secure")
if hc.TLSVerify {
attr = append(attr, "verify")
}
}
s := strings.Join(attr, "; ")
return fmt.Sprintf("HTTP %s %s [%s] %s", hc.Method, hc.Request, s, hc.Target)
} | [
"func",
"(",
"hc",
"*",
"HTTPChecker",
")",
"String",
"(",
")",
"string",
"{",
"attr",
":=",
"[",
"]",
"string",
"{",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"hc",
".",
"ResponseCode",
")",
"}",
"\n",
"if",
"hc",
".",
"Proxy",
"{",
"attr",
"=",
"append",
"(",
"attr",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"hc",
".",
"Secure",
"{",
"attr",
"=",
"append",
"(",
"attr",
",",
"\"",
"\"",
")",
"\n",
"if",
"hc",
".",
"TLSVerify",
"{",
"attr",
"=",
"append",
"(",
"attr",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"s",
":=",
"strings",
".",
"Join",
"(",
"attr",
",",
"\"",
"\"",
")",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"hc",
".",
"Method",
",",
"hc",
".",
"Request",
",",
"s",
",",
"hc",
".",
"Target",
")",
"\n",
"}"
] | // String returns the string representation of an HTTP healthcheck. | [
"String",
"returns",
"the",
"string",
"representation",
"of",
"an",
"HTTP",
"healthcheck",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/http.go#L70-L83 | train |
google/seesaw | healthcheck/tcp.go | NewTCPChecker | func NewTCPChecker(ip net.IP, port int) *TCPChecker {
return &TCPChecker{
Target: Target{
IP: ip,
Port: port,
Proto: seesaw.IPProtoTCP,
},
}
} | go | func NewTCPChecker(ip net.IP, port int) *TCPChecker {
return &TCPChecker{
Target: Target{
IP: ip,
Port: port,
Proto: seesaw.IPProtoTCP,
},
}
} | [
"func",
"NewTCPChecker",
"(",
"ip",
"net",
".",
"IP",
",",
"port",
"int",
")",
"*",
"TCPChecker",
"{",
"return",
"&",
"TCPChecker",
"{",
"Target",
":",
"Target",
"{",
"IP",
":",
"ip",
",",
"Port",
":",
"port",
",",
"Proto",
":",
"seesaw",
".",
"IPProtoTCP",
",",
"}",
",",
"}",
"\n",
"}"
] | // NewTCPChecker returns an initialised TCPChecker. | [
"NewTCPChecker",
"returns",
"an",
"initialised",
"TCPChecker",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/tcp.go#L46-L54 | train |
google/seesaw | healthcheck/tcp.go | String | func (hc *TCPChecker) String() string {
attr := []string{}
if hc.Secure {
attr = append(attr, "secure")
if hc.TLSVerify {
attr = append(attr, "verify")
}
}
var s string
if len(attr) > 0 {
s = fmt.Sprintf(" [%s]", strings.Join(attr, "; "))
}
return fmt.Sprintf("TCP%s %s", s, hc.Target)
} | go | func (hc *TCPChecker) String() string {
attr := []string{}
if hc.Secure {
attr = append(attr, "secure")
if hc.TLSVerify {
attr = append(attr, "verify")
}
}
var s string
if len(attr) > 0 {
s = fmt.Sprintf(" [%s]", strings.Join(attr, "; "))
}
return fmt.Sprintf("TCP%s %s", s, hc.Target)
} | [
"func",
"(",
"hc",
"*",
"TCPChecker",
")",
"String",
"(",
")",
"string",
"{",
"attr",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"if",
"hc",
".",
"Secure",
"{",
"attr",
"=",
"append",
"(",
"attr",
",",
"\"",
"\"",
")",
"\n",
"if",
"hc",
".",
"TLSVerify",
"{",
"attr",
"=",
"append",
"(",
"attr",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"var",
"s",
"string",
"\n",
"if",
"len",
"(",
"attr",
")",
">",
"0",
"{",
"s",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"strings",
".",
"Join",
"(",
"attr",
",",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"s",
",",
"hc",
".",
"Target",
")",
"\n",
"}"
] | // String returns the string representation of a TCP healthcheck. | [
"String",
"returns",
"the",
"string",
"representation",
"of",
"a",
"TCP",
"healthcheck",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/tcp.go#L57-L70 | train |
google/seesaw | healthcheck/tcp.go | Check | func (hc *TCPChecker) Check(timeout time.Duration) *Result {
msg := fmt.Sprintf("TCP connect to %s", hc.addr())
start := time.Now()
if timeout == time.Duration(0) {
timeout = defaultTCPTimeout
}
deadline := start.Add(timeout)
tcpConn, err := dialTCP(hc.network(), hc.addr(), timeout, hc.Mark)
if err != nil {
msg = fmt.Sprintf("%s; failed to connect", msg)
return complete(start, msg, false, err)
}
conn := net.Conn(tcpConn)
defer conn.Close()
// Negotiate TLS if this is required.
if hc.Secure {
// TODO(jsing): We probably should allow the server name to
// be specified via configuration...
host, _, err := net.SplitHostPort(hc.addr())
if err != nil {
msg = msg + "; failed to split host"
return complete(start, msg, false, err)
}
tlsConfig := &tls.Config{
InsecureSkipVerify: !hc.TLSVerify,
ServerName: host,
}
tlsConn := tls.Client(conn, tlsConfig)
if err := tlsConn.Handshake(); err != nil {
return complete(start, msg, false, err)
}
conn = tlsConn
}
if hc.Send == "" && hc.Receive == "" {
return complete(start, msg, true, err)
}
err = conn.SetDeadline(deadline)
if err != nil {
msg = fmt.Sprintf("%s; failed to set deadline", msg)
return complete(start, msg, false, err)
}
if hc.Send != "" {
err = writeFull(conn, []byte(hc.Send))
if err != nil {
msg = fmt.Sprintf("%s; failed to send request", msg)
return complete(start, msg, false, err)
}
}
if hc.Receive != "" {
buf := make([]byte, len(hc.Receive))
n, err := io.ReadFull(conn, buf)
if err != nil {
msg = fmt.Sprintf("%s; failed to read response", msg)
return complete(start, msg, false, err)
}
got := string(buf[0:n])
if got != hc.Receive {
msg = fmt.Sprintf("%s; unexpected response - %q", msg, got)
return complete(start, msg, false, err)
}
}
return complete(start, msg, true, err)
} | go | func (hc *TCPChecker) Check(timeout time.Duration) *Result {
msg := fmt.Sprintf("TCP connect to %s", hc.addr())
start := time.Now()
if timeout == time.Duration(0) {
timeout = defaultTCPTimeout
}
deadline := start.Add(timeout)
tcpConn, err := dialTCP(hc.network(), hc.addr(), timeout, hc.Mark)
if err != nil {
msg = fmt.Sprintf("%s; failed to connect", msg)
return complete(start, msg, false, err)
}
conn := net.Conn(tcpConn)
defer conn.Close()
// Negotiate TLS if this is required.
if hc.Secure {
// TODO(jsing): We probably should allow the server name to
// be specified via configuration...
host, _, err := net.SplitHostPort(hc.addr())
if err != nil {
msg = msg + "; failed to split host"
return complete(start, msg, false, err)
}
tlsConfig := &tls.Config{
InsecureSkipVerify: !hc.TLSVerify,
ServerName: host,
}
tlsConn := tls.Client(conn, tlsConfig)
if err := tlsConn.Handshake(); err != nil {
return complete(start, msg, false, err)
}
conn = tlsConn
}
if hc.Send == "" && hc.Receive == "" {
return complete(start, msg, true, err)
}
err = conn.SetDeadline(deadline)
if err != nil {
msg = fmt.Sprintf("%s; failed to set deadline", msg)
return complete(start, msg, false, err)
}
if hc.Send != "" {
err = writeFull(conn, []byte(hc.Send))
if err != nil {
msg = fmt.Sprintf("%s; failed to send request", msg)
return complete(start, msg, false, err)
}
}
if hc.Receive != "" {
buf := make([]byte, len(hc.Receive))
n, err := io.ReadFull(conn, buf)
if err != nil {
msg = fmt.Sprintf("%s; failed to read response", msg)
return complete(start, msg, false, err)
}
got := string(buf[0:n])
if got != hc.Receive {
msg = fmt.Sprintf("%s; unexpected response - %q", msg, got)
return complete(start, msg, false, err)
}
}
return complete(start, msg, true, err)
} | [
"func",
"(",
"hc",
"*",
"TCPChecker",
")",
"Check",
"(",
"timeout",
"time",
".",
"Duration",
")",
"*",
"Result",
"{",
"msg",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"hc",
".",
"addr",
"(",
")",
")",
"\n",
"start",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"if",
"timeout",
"==",
"time",
".",
"Duration",
"(",
"0",
")",
"{",
"timeout",
"=",
"defaultTCPTimeout",
"\n",
"}",
"\n",
"deadline",
":=",
"start",
".",
"Add",
"(",
"timeout",
")",
"\n\n",
"tcpConn",
",",
"err",
":=",
"dialTCP",
"(",
"hc",
".",
"network",
"(",
")",
",",
"hc",
".",
"addr",
"(",
")",
",",
"timeout",
",",
"hc",
".",
"Mark",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"msg",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"msg",
")",
"\n",
"return",
"complete",
"(",
"start",
",",
"msg",
",",
"false",
",",
"err",
")",
"\n",
"}",
"\n",
"conn",
":=",
"net",
".",
"Conn",
"(",
"tcpConn",
")",
"\n",
"defer",
"conn",
".",
"Close",
"(",
")",
"\n\n",
"// Negotiate TLS if this is required.",
"if",
"hc",
".",
"Secure",
"{",
"// TODO(jsing): We probably should allow the server name to",
"// be specified via configuration...",
"host",
",",
"_",
",",
"err",
":=",
"net",
".",
"SplitHostPort",
"(",
"hc",
".",
"addr",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"msg",
"=",
"msg",
"+",
"\"",
"\"",
"\n",
"return",
"complete",
"(",
"start",
",",
"msg",
",",
"false",
",",
"err",
")",
"\n",
"}",
"\n",
"tlsConfig",
":=",
"&",
"tls",
".",
"Config",
"{",
"InsecureSkipVerify",
":",
"!",
"hc",
".",
"TLSVerify",
",",
"ServerName",
":",
"host",
",",
"}",
"\n",
"tlsConn",
":=",
"tls",
".",
"Client",
"(",
"conn",
",",
"tlsConfig",
")",
"\n",
"if",
"err",
":=",
"tlsConn",
".",
"Handshake",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"complete",
"(",
"start",
",",
"msg",
",",
"false",
",",
"err",
")",
"\n",
"}",
"\n",
"conn",
"=",
"tlsConn",
"\n",
"}",
"\n\n",
"if",
"hc",
".",
"Send",
"==",
"\"",
"\"",
"&&",
"hc",
".",
"Receive",
"==",
"\"",
"\"",
"{",
"return",
"complete",
"(",
"start",
",",
"msg",
",",
"true",
",",
"err",
")",
"\n",
"}",
"\n\n",
"err",
"=",
"conn",
".",
"SetDeadline",
"(",
"deadline",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"msg",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"msg",
")",
"\n",
"return",
"complete",
"(",
"start",
",",
"msg",
",",
"false",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"hc",
".",
"Send",
"!=",
"\"",
"\"",
"{",
"err",
"=",
"writeFull",
"(",
"conn",
",",
"[",
"]",
"byte",
"(",
"hc",
".",
"Send",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"msg",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"msg",
")",
"\n",
"return",
"complete",
"(",
"start",
",",
"msg",
",",
"false",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"hc",
".",
"Receive",
"!=",
"\"",
"\"",
"{",
"buf",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"len",
"(",
"hc",
".",
"Receive",
")",
")",
"\n",
"n",
",",
"err",
":=",
"io",
".",
"ReadFull",
"(",
"conn",
",",
"buf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"msg",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"msg",
")",
"\n",
"return",
"complete",
"(",
"start",
",",
"msg",
",",
"false",
",",
"err",
")",
"\n",
"}",
"\n",
"got",
":=",
"string",
"(",
"buf",
"[",
"0",
":",
"n",
"]",
")",
"\n",
"if",
"got",
"!=",
"hc",
".",
"Receive",
"{",
"msg",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"msg",
",",
"got",
")",
"\n",
"return",
"complete",
"(",
"start",
",",
"msg",
",",
"false",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"complete",
"(",
"start",
",",
"msg",
",",
"true",
",",
"err",
")",
"\n",
"}"
] | // Check executes a TCP healthcheck. | [
"Check",
"executes",
"a",
"TCP",
"healthcheck",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/tcp.go#L73-L141 | train |
google/seesaw | ncc/types/ncc_types.go | Interface | func (lb *LBInterface) Interface() (*net.Interface, error) {
iface, err := net.InterfaceByName(lb.Name)
if err != nil {
return nil, err
}
return iface, nil
} | go | func (lb *LBInterface) Interface() (*net.Interface, error) {
iface, err := net.InterfaceByName(lb.Name)
if err != nil {
return nil, err
}
return iface, nil
} | [
"func",
"(",
"lb",
"*",
"LBInterface",
")",
"Interface",
"(",
")",
"(",
"*",
"net",
".",
"Interface",
",",
"error",
")",
"{",
"iface",
",",
"err",
":=",
"net",
".",
"InterfaceByName",
"(",
"lb",
".",
"Name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"iface",
",",
"nil",
"\n",
"}"
] | // Interface returns the network interface associated with the LBInterface. | [
"Interface",
"returns",
"the",
"network",
"interface",
"associated",
"with",
"the",
"LBInterface",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/types/ncc_types.go#L73-L79 | train |
google/seesaw | cli/show.go | label | func label(l string, indent, width int) string {
pad := width - indent - len(l)
if pad < 0 {
pad = 0
}
return fmt.Sprintf("%s%s%s", strings.Repeat(" ", indent), l,
strings.Repeat(" ", pad))
} | go | func label(l string, indent, width int) string {
pad := width - indent - len(l)
if pad < 0 {
pad = 0
}
return fmt.Sprintf("%s%s%s", strings.Repeat(" ", indent), l,
strings.Repeat(" ", pad))
} | [
"func",
"label",
"(",
"l",
"string",
",",
"indent",
",",
"width",
"int",
")",
"string",
"{",
"pad",
":=",
"width",
"-",
"indent",
"-",
"len",
"(",
"l",
")",
"\n",
"if",
"pad",
"<",
"0",
"{",
"pad",
"=",
"0",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"strings",
".",
"Repeat",
"(",
"\"",
"\"",
",",
"indent",
")",
",",
"l",
",",
"strings",
".",
"Repeat",
"(",
"\"",
"\"",
",",
"pad",
")",
")",
"\n",
"}"
] | // label returns a string containing the label with indentation and padding. | [
"label",
"returns",
"a",
"string",
"containing",
"the",
"label",
"with",
"indentation",
"and",
"padding",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/cli/show.go#L554-L561 | train |
google/seesaw | cli/show.go | printFmt | func printFmt(l, v string, args ...interface{}) {
l = label(l, subIndent, valIndent)
fmt.Printf("%s %s\n", l, fmt.Sprintf(v, args...))
} | go | func printFmt(l, v string, args ...interface{}) {
l = label(l, subIndent, valIndent)
fmt.Printf("%s %s\n", l, fmt.Sprintf(v, args...))
} | [
"func",
"printFmt",
"(",
"l",
",",
"v",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"l",
"=",
"label",
"(",
"l",
",",
"subIndent",
",",
"valIndent",
")",
"\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"l",
",",
"fmt",
".",
"Sprintf",
"(",
"v",
",",
"args",
"...",
")",
")",
"\n",
"}"
] | // printFmt formats and prints a given value with the specified label. | [
"printFmt",
"formats",
"and",
"prints",
"a",
"given",
"value",
"with",
"the",
"specified",
"label",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/cli/show.go#L569-L572 | train |
google/seesaw | cli/show.go | printVal | func printVal(l string, v interface{}) {
switch f := v.(type) {
case uint, uint64:
printFmt(l, "%d", f)
case string:
printFmt(l, "%s", f)
default:
printFmt(l, "%v", f)
}
} | go | func printVal(l string, v interface{}) {
switch f := v.(type) {
case uint, uint64:
printFmt(l, "%d", f)
case string:
printFmt(l, "%s", f)
default:
printFmt(l, "%v", f)
}
} | [
"func",
"printVal",
"(",
"l",
"string",
",",
"v",
"interface",
"{",
"}",
")",
"{",
"switch",
"f",
":=",
"v",
".",
"(",
"type",
")",
"{",
"case",
"uint",
",",
"uint64",
":",
"printFmt",
"(",
"l",
",",
"\"",
"\"",
",",
"f",
")",
"\n",
"case",
"string",
":",
"printFmt",
"(",
"l",
",",
"\"",
"\"",
",",
"f",
")",
"\n",
"default",
":",
"printFmt",
"(",
"l",
",",
"\"",
"\"",
",",
"f",
")",
"\n",
"}",
"\n",
"}"
] | // printVal prints the given value with the specified label. | [
"printVal",
"prints",
"the",
"given",
"value",
"with",
"the",
"specified",
"label",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/cli/show.go#L575-L584 | train |
google/seesaw | engine/sync.go | String | func (snt SyncNoteType) String() string {
if name, ok := syncNoteTypeNames[snt]; ok {
return name
}
return fmt.Sprintf("(Unknown %d)", snt)
} | go | func (snt SyncNoteType) String() string {
if name, ok := syncNoteTypeNames[snt]; ok {
return name
}
return fmt.Sprintf("(Unknown %d)", snt)
} | [
"func",
"(",
"snt",
"SyncNoteType",
")",
"String",
"(",
")",
"string",
"{",
"if",
"name",
",",
"ok",
":=",
"syncNoteTypeNames",
"[",
"snt",
"]",
";",
"ok",
"{",
"return",
"name",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"snt",
")",
"\n",
"}"
] | // String returns the string representation of a synchronisation notification
// type. | [
"String",
"returns",
"the",
"string",
"representation",
"of",
"a",
"synchronisation",
"notification",
"type",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/sync.go#L73-L78 | train |
google/seesaw | engine/sync.go | Register | func (s *SeesawSync) Register(node net.IP, id *SyncSessionID) error {
if id == nil {
return errors.New("id is nil")
}
// TODO(jsing): Reject if not master?
s.sync.sessionLock.Lock()
session := newSyncSession(node, s.sync.nextSessionID)
s.sync.nextSessionID++
s.sync.sessions[session.id] = session
s.sync.sessionLock.Unlock()
session.Lock()
session.expiryTime = time.Now().Add(sessionDeadtime)
session.Unlock()
*id = session.id
log.Infof("Synchronisation session %d registered by %v", *id, node)
return nil
} | go | func (s *SeesawSync) Register(node net.IP, id *SyncSessionID) error {
if id == nil {
return errors.New("id is nil")
}
// TODO(jsing): Reject if not master?
s.sync.sessionLock.Lock()
session := newSyncSession(node, s.sync.nextSessionID)
s.sync.nextSessionID++
s.sync.sessions[session.id] = session
s.sync.sessionLock.Unlock()
session.Lock()
session.expiryTime = time.Now().Add(sessionDeadtime)
session.Unlock()
*id = session.id
log.Infof("Synchronisation session %d registered by %v", *id, node)
return nil
} | [
"func",
"(",
"s",
"*",
"SeesawSync",
")",
"Register",
"(",
"node",
"net",
".",
"IP",
",",
"id",
"*",
"SyncSessionID",
")",
"error",
"{",
"if",
"id",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// TODO(jsing): Reject if not master?",
"s",
".",
"sync",
".",
"sessionLock",
".",
"Lock",
"(",
")",
"\n",
"session",
":=",
"newSyncSession",
"(",
"node",
",",
"s",
".",
"sync",
".",
"nextSessionID",
")",
"\n",
"s",
".",
"sync",
".",
"nextSessionID",
"++",
"\n",
"s",
".",
"sync",
".",
"sessions",
"[",
"session",
".",
"id",
"]",
"=",
"session",
"\n",
"s",
".",
"sync",
".",
"sessionLock",
".",
"Unlock",
"(",
")",
"\n\n",
"session",
".",
"Lock",
"(",
")",
"\n",
"session",
".",
"expiryTime",
"=",
"time",
".",
"Now",
"(",
")",
".",
"Add",
"(",
"sessionDeadtime",
")",
"\n",
"session",
".",
"Unlock",
"(",
")",
"\n\n",
"*",
"id",
"=",
"session",
".",
"id",
"\n\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"*",
"id",
",",
"node",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Register registers our Seesaw peer for synchronisation notifications. | [
"Register",
"registers",
"our",
"Seesaw",
"peer",
"for",
"synchronisation",
"notifications",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/sync.go#L103-L125 | train |
google/seesaw | engine/sync.go | Deregister | func (s *SeesawSync) Deregister(id SyncSessionID, reply *int) error {
s.sync.sessionLock.Lock()
session, ok := s.sync.sessions[id]
delete(s.sync.sessions, id)
s.sync.sessionLock.Unlock()
if ok {
log.Infof("Synchronisation session %d deregistered with %v", id, session.node)
}
return nil
} | go | func (s *SeesawSync) Deregister(id SyncSessionID, reply *int) error {
s.sync.sessionLock.Lock()
session, ok := s.sync.sessions[id]
delete(s.sync.sessions, id)
s.sync.sessionLock.Unlock()
if ok {
log.Infof("Synchronisation session %d deregistered with %v", id, session.node)
}
return nil
} | [
"func",
"(",
"s",
"*",
"SeesawSync",
")",
"Deregister",
"(",
"id",
"SyncSessionID",
",",
"reply",
"*",
"int",
")",
"error",
"{",
"s",
".",
"sync",
".",
"sessionLock",
".",
"Lock",
"(",
")",
"\n",
"session",
",",
"ok",
":=",
"s",
".",
"sync",
".",
"sessions",
"[",
"id",
"]",
"\n",
"delete",
"(",
"s",
".",
"sync",
".",
"sessions",
",",
"id",
")",
"\n",
"s",
".",
"sync",
".",
"sessionLock",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"ok",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"id",
",",
"session",
".",
"node",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Deregister deregisters a Seesaw peer for synchronisation. | [
"Deregister",
"deregisters",
"a",
"Seesaw",
"peer",
"for",
"synchronisation",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/sync.go#L128-L139 | train |
google/seesaw | engine/sync.go | Poll | func (s *SeesawSync) Poll(id SyncSessionID, sn *SyncNotes) error {
if sn == nil {
return errors.New("sync notes is nil")
}
s.sync.sessionLock.RLock()
session, ok := s.sync.sessions[id]
s.sync.sessionLock.RUnlock()
if !ok {
return errors.New("no session with ID %d")
}
// Reset expiry time and check for desynchronisation.
session.Lock()
session.expiryTime = time.Now().Add(sessionDeadtime)
if session.desync {
// TODO(jsing): Discard pending notes?
sn.Notes = append(sn.Notes, SyncNote{Type: SNTDesync})
session.desync = false
session.Unlock()
return nil
}
session.Unlock()
// Block until a notification becomes available or our poll expires.
select {
case note := <-session.notes:
sn.Notes = append(sn.Notes, *note)
case <-time.After(syncPollTimeout):
return errors.New("poll timeout")
}
pollLoop:
for i := 0; i < syncPollMsgLimit; i++ {
select {
case note := <-session.notes:
sn.Notes = append(sn.Notes, *note)
default:
break pollLoop
}
}
log.V(1).Infof("Sync server poll returning %d notifications", len(sn.Notes))
return nil
} | go | func (s *SeesawSync) Poll(id SyncSessionID, sn *SyncNotes) error {
if sn == nil {
return errors.New("sync notes is nil")
}
s.sync.sessionLock.RLock()
session, ok := s.sync.sessions[id]
s.sync.sessionLock.RUnlock()
if !ok {
return errors.New("no session with ID %d")
}
// Reset expiry time and check for desynchronisation.
session.Lock()
session.expiryTime = time.Now().Add(sessionDeadtime)
if session.desync {
// TODO(jsing): Discard pending notes?
sn.Notes = append(sn.Notes, SyncNote{Type: SNTDesync})
session.desync = false
session.Unlock()
return nil
}
session.Unlock()
// Block until a notification becomes available or our poll expires.
select {
case note := <-session.notes:
sn.Notes = append(sn.Notes, *note)
case <-time.After(syncPollTimeout):
return errors.New("poll timeout")
}
pollLoop:
for i := 0; i < syncPollMsgLimit; i++ {
select {
case note := <-session.notes:
sn.Notes = append(sn.Notes, *note)
default:
break pollLoop
}
}
log.V(1).Infof("Sync server poll returning %d notifications", len(sn.Notes))
return nil
} | [
"func",
"(",
"s",
"*",
"SeesawSync",
")",
"Poll",
"(",
"id",
"SyncSessionID",
",",
"sn",
"*",
"SyncNotes",
")",
"error",
"{",
"if",
"sn",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"s",
".",
"sync",
".",
"sessionLock",
".",
"RLock",
"(",
")",
"\n",
"session",
",",
"ok",
":=",
"s",
".",
"sync",
".",
"sessions",
"[",
"id",
"]",
"\n",
"s",
".",
"sync",
".",
"sessionLock",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Reset expiry time and check for desynchronisation.",
"session",
".",
"Lock",
"(",
")",
"\n",
"session",
".",
"expiryTime",
"=",
"time",
".",
"Now",
"(",
")",
".",
"Add",
"(",
"sessionDeadtime",
")",
"\n",
"if",
"session",
".",
"desync",
"{",
"// TODO(jsing): Discard pending notes?",
"sn",
".",
"Notes",
"=",
"append",
"(",
"sn",
".",
"Notes",
",",
"SyncNote",
"{",
"Type",
":",
"SNTDesync",
"}",
")",
"\n",
"session",
".",
"desync",
"=",
"false",
"\n",
"session",
".",
"Unlock",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"session",
".",
"Unlock",
"(",
")",
"\n\n",
"// Block until a notification becomes available or our poll expires.",
"select",
"{",
"case",
"note",
":=",
"<-",
"session",
".",
"notes",
":",
"sn",
".",
"Notes",
"=",
"append",
"(",
"sn",
".",
"Notes",
",",
"*",
"note",
")",
"\n",
"case",
"<-",
"time",
".",
"After",
"(",
"syncPollTimeout",
")",
":",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"pollLoop",
":",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"syncPollMsgLimit",
";",
"i",
"++",
"{",
"select",
"{",
"case",
"note",
":=",
"<-",
"session",
".",
"notes",
":",
"sn",
".",
"Notes",
"=",
"append",
"(",
"sn",
".",
"Notes",
",",
"*",
"note",
")",
"\n",
"default",
":",
"break",
"pollLoop",
"\n",
"}",
"\n",
"}",
"\n\n",
"log",
".",
"V",
"(",
"1",
")",
".",
"Infof",
"(",
"\"",
"\"",
",",
"len",
"(",
"sn",
".",
"Notes",
")",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Poll returns one or more synchronisation notifications to the caller,
// blocking until at least one notification becomes available or the poll
// timeout is reached. | [
"Poll",
"returns",
"one",
"or",
"more",
"synchronisation",
"notifications",
"to",
"the",
"caller",
"blocking",
"until",
"at",
"least",
"one",
"notification",
"becomes",
"available",
"or",
"the",
"poll",
"timeout",
"is",
"reached",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/sync.go#L144-L188 | train |
google/seesaw | engine/sync.go | Config | func (s *SeesawSync) Config(arg int, config *config.Notification) error {
return errors.New("unimplemented")
} | go | func (s *SeesawSync) Config(arg int, config *config.Notification) error {
return errors.New("unimplemented")
} | [
"func",
"(",
"s",
"*",
"SeesawSync",
")",
"Config",
"(",
"arg",
"int",
",",
"config",
"*",
"config",
".",
"Notification",
")",
"error",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // Config requests the current configuration from the peer Seesaw node. | [
"Config",
"requests",
"the",
"current",
"configuration",
"from",
"the",
"peer",
"Seesaw",
"node",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/sync.go#L191-L193 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.