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 | common/conn/conn.go | RegisterEngineConn | func RegisterEngineConn(connType string, connFunc func(ctx *ipc.Context) EngineConn) {
engineConns[connType] = connFunc
} | go | func RegisterEngineConn(connType string, connFunc func(ctx *ipc.Context) EngineConn) {
engineConns[connType] = connFunc
} | [
"func",
"RegisterEngineConn",
"(",
"connType",
"string",
",",
"connFunc",
"func",
"(",
"ctx",
"*",
"ipc",
".",
"Context",
")",
"EngineConn",
")",
"{",
"engineConns",
"[",
"connType",
"]",
"=",
"connFunc",
"\n",
"}"
] | // RegisterEngineConn registers the given connection type. | [
"RegisterEngineConn",
"registers",
"the",
"given",
"connection",
"type",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/conn/conn.go#L59-L61 | train |
google/seesaw | common/conn/conn.go | NewSeesawIPC | func NewSeesawIPC(ctx *ipc.Context) (*Seesaw, error) {
if newConn, ok := engineConns["ipc"]; ok {
return &Seesaw{newConn(ctx)}, nil
}
return nil, errors.New("No Seesaw IPC connection type registered")
} | go | func NewSeesawIPC(ctx *ipc.Context) (*Seesaw, error) {
if newConn, ok := engineConns["ipc"]; ok {
return &Seesaw{newConn(ctx)}, nil
}
return nil, errors.New("No Seesaw IPC connection type registered")
} | [
"func",
"NewSeesawIPC",
"(",
"ctx",
"*",
"ipc",
".",
"Context",
")",
"(",
"*",
"Seesaw",
",",
"error",
")",
"{",
"if",
"newConn",
",",
"ok",
":=",
"engineConns",
"[",
"\"",
"\"",
"]",
";",
"ok",
"{",
"return",
"&",
"Seesaw",
"{",
"newConn",
"(",
"ctx",
")",
"}",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // NewSeesawIPC returns a new Seesaw IPC connection. | [
"NewSeesawIPC",
"returns",
"a",
"new",
"Seesaw",
"IPC",
"connection",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/conn/conn.go#L69-L74 | train |
google/seesaw | binaries/seesaw_watchdog/main.go | svcOpt | func svcOpt(cfg *conf.ConfigFile, service, option string, required bool) string {
// TODO(jsing): Add support for defaults.
opt := cfgOpt(cfg, service, option)
if opt == "" && required {
log.Fatalf("Service %s has missing %s option", service, option)
}
return opt
} | go | func svcOpt(cfg *conf.ConfigFile, service, option string, required bool) string {
// TODO(jsing): Add support for defaults.
opt := cfgOpt(cfg, service, option)
if opt == "" && required {
log.Fatalf("Service %s has missing %s option", service, option)
}
return opt
} | [
"func",
"svcOpt",
"(",
"cfg",
"*",
"conf",
".",
"ConfigFile",
",",
"service",
",",
"option",
"string",
",",
"required",
"bool",
")",
"string",
"{",
"// TODO(jsing): Add support for defaults.",
"opt",
":=",
"cfgOpt",
"(",
"cfg",
",",
"service",
",",
"option",
")",
"\n",
"if",
"opt",
"==",
"\"",
"\"",
"&&",
"required",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"service",
",",
"option",
")",
"\n",
"}",
"\n",
"return",
"opt",
"\n",
"}"
] | // svcOpt returns the specified configuration option for a service. | [
"svcOpt",
"returns",
"the",
"specified",
"configuration",
"option",
"for",
"a",
"service",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/binaries/seesaw_watchdog/main.go#L53-L60 | train |
google/seesaw | engine/ipc.go | Failover | func (s *SeesawEngine) Failover(ctx *ipc.Context, reply *int) error {
s.trace("Failover", ctx)
if ctx == nil {
return errors.New("context is nil")
}
if !ctx.IsTrusted() {
return errors.New("insufficient access")
}
return s.engine.haManager.requestFailover(false)
} | go | func (s *SeesawEngine) Failover(ctx *ipc.Context, reply *int) error {
s.trace("Failover", ctx)
if ctx == nil {
return errors.New("context is nil")
}
if !ctx.IsTrusted() {
return errors.New("insufficient access")
}
return s.engine.haManager.requestFailover(false)
} | [
"func",
"(",
"s",
"*",
"SeesawEngine",
")",
"Failover",
"(",
"ctx",
"*",
"ipc",
".",
"Context",
",",
"reply",
"*",
"int",
")",
"error",
"{",
"s",
".",
"trace",
"(",
"\"",
"\"",
",",
"ctx",
")",
"\n",
"if",
"ctx",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"ctx",
".",
"IsTrusted",
"(",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"s",
".",
"engine",
".",
"haManager",
".",
"requestFailover",
"(",
"false",
")",
"\n",
"}"
] | // Failover requests the Seesaw Engine to relinquish master state. | [
"Failover",
"requests",
"the",
"Seesaw",
"Engine",
"to",
"relinquish",
"master",
"state",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/ipc.go#L51-L62 | train |
google/seesaw | engine/ipc.go | HAConfig | func (s *SeesawEngine) HAConfig(ctx *ipc.Context, reply *seesaw.HAConfig) error {
s.trace("HAConfig", ctx)
if ctx == nil {
return errors.New("context is nil")
}
if !ctx.IsTrusted() {
return errors.New("insufficient access")
}
c, err := s.engine.haConfig()
if err != nil {
return err
}
if reply != nil {
reply.Copy(c)
}
return nil
} | go | func (s *SeesawEngine) HAConfig(ctx *ipc.Context, reply *seesaw.HAConfig) error {
s.trace("HAConfig", ctx)
if ctx == nil {
return errors.New("context is nil")
}
if !ctx.IsTrusted() {
return errors.New("insufficient access")
}
c, err := s.engine.haConfig()
if err != nil {
return err
}
if reply != nil {
reply.Copy(c)
}
return nil
} | [
"func",
"(",
"s",
"*",
"SeesawEngine",
")",
"HAConfig",
"(",
"ctx",
"*",
"ipc",
".",
"Context",
",",
"reply",
"*",
"seesaw",
".",
"HAConfig",
")",
"error",
"{",
"s",
".",
"trace",
"(",
"\"",
"\"",
",",
"ctx",
")",
"\n",
"if",
"ctx",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"ctx",
".",
"IsTrusted",
"(",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"c",
",",
"err",
":=",
"s",
".",
"engine",
".",
"haConfig",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"reply",
"!=",
"nil",
"{",
"reply",
".",
"Copy",
"(",
"c",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // HAConfig returns the high-availability configuration for this node as
// determined by the engine. | [
"HAConfig",
"returns",
"the",
"high",
"-",
"availability",
"configuration",
"for",
"this",
"node",
"as",
"determined",
"by",
"the",
"engine",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/ipc.go#L66-L84 | train |
google/seesaw | engine/ipc.go | HAUpdate | func (s *SeesawEngine) HAUpdate(args *ipc.HAStatus, failover *bool) error {
if args == nil {
return errors.New("args is nil")
}
ctx := args.Ctx
s.trace("HAUpdate", ctx)
if ctx == nil {
return errors.New("context is nil")
}
if !ctx.IsTrusted() {
return errors.New("insufficient access")
}
s.engine.setHAStatus(args.Status)
if failover != nil {
*failover = s.engine.haManager.failover()
}
return nil
} | go | func (s *SeesawEngine) HAUpdate(args *ipc.HAStatus, failover *bool) error {
if args == nil {
return errors.New("args is nil")
}
ctx := args.Ctx
s.trace("HAUpdate", ctx)
if ctx == nil {
return errors.New("context is nil")
}
if !ctx.IsTrusted() {
return errors.New("insufficient access")
}
s.engine.setHAStatus(args.Status)
if failover != nil {
*failover = s.engine.haManager.failover()
}
return nil
} | [
"func",
"(",
"s",
"*",
"SeesawEngine",
")",
"HAUpdate",
"(",
"args",
"*",
"ipc",
".",
"HAStatus",
",",
"failover",
"*",
"bool",
")",
"error",
"{",
"if",
"args",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"ctx",
":=",
"args",
".",
"Ctx",
"\n",
"s",
".",
"trace",
"(",
"\"",
"\"",
",",
"ctx",
")",
"\n",
"if",
"ctx",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"ctx",
".",
"IsTrusted",
"(",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"s",
".",
"engine",
".",
"setHAStatus",
"(",
"args",
".",
"Status",
")",
"\n",
"if",
"failover",
"!=",
"nil",
"{",
"*",
"failover",
"=",
"s",
".",
"engine",
".",
"haManager",
".",
"failover",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // HAUpdate advises the Engine of the current high-availability status for
// the Seesaw HA component. The Seesaw Engine may also request a failover
// in response. | [
"HAUpdate",
"advises",
"the",
"Engine",
"of",
"the",
"current",
"high",
"-",
"availability",
"status",
"for",
"the",
"Seesaw",
"HA",
"component",
".",
"The",
"Seesaw",
"Engine",
"may",
"also",
"request",
"a",
"failover",
"in",
"response",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/ipc.go#L89-L108 | train |
google/seesaw | engine/ipc.go | HAState | func (s *SeesawEngine) HAState(args *ipc.HAState, reply *int) error {
if args == nil {
return errors.New("args is nil")
}
ctx := args.Ctx
s.trace("HAState", ctx)
if ctx == nil {
return errors.New("context is nil")
}
if !ctx.IsTrusted() {
return errors.New("insufficient access")
}
s.engine.setHAState(args.State)
return nil
} | go | func (s *SeesawEngine) HAState(args *ipc.HAState, reply *int) error {
if args == nil {
return errors.New("args is nil")
}
ctx := args.Ctx
s.trace("HAState", ctx)
if ctx == nil {
return errors.New("context is nil")
}
if !ctx.IsTrusted() {
return errors.New("insufficient access")
}
s.engine.setHAState(args.State)
return nil
} | [
"func",
"(",
"s",
"*",
"SeesawEngine",
")",
"HAState",
"(",
"args",
"*",
"ipc",
".",
"HAState",
",",
"reply",
"*",
"int",
")",
"error",
"{",
"if",
"args",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"ctx",
":=",
"args",
".",
"Ctx",
"\n",
"s",
".",
"trace",
"(",
"\"",
"\"",
",",
"ctx",
")",
"\n",
"if",
"ctx",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"ctx",
".",
"IsTrusted",
"(",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"s",
".",
"engine",
".",
"setHAState",
"(",
"args",
".",
"State",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // HAState advises the Engine of the current high-availability state as
// determined by the Seesaw HA component. | [
"HAState",
"advises",
"the",
"Engine",
"of",
"the",
"current",
"high",
"-",
"availability",
"state",
"as",
"determined",
"by",
"the",
"Seesaw",
"HA",
"component",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/ipc.go#L112-L128 | train |
google/seesaw | engine/ipc.go | Healthchecks | func (s *SeesawEngine) Healthchecks(ctx *ipc.Context, reply *healthcheck.Checks) error {
s.trace("Healthchecks", ctx)
if ctx == nil {
return errors.New("context is nil")
}
if !ctx.IsTrusted() {
return errors.New("insufficient access")
}
configs := s.engine.hcManager.configs()
if reply != nil {
reply.Configs = configs
}
return nil
} | go | func (s *SeesawEngine) Healthchecks(ctx *ipc.Context, reply *healthcheck.Checks) error {
s.trace("Healthchecks", ctx)
if ctx == nil {
return errors.New("context is nil")
}
if !ctx.IsTrusted() {
return errors.New("insufficient access")
}
configs := s.engine.hcManager.configs()
if reply != nil {
reply.Configs = configs
}
return nil
} | [
"func",
"(",
"s",
"*",
"SeesawEngine",
")",
"Healthchecks",
"(",
"ctx",
"*",
"ipc",
".",
"Context",
",",
"reply",
"*",
"healthcheck",
".",
"Checks",
")",
"error",
"{",
"s",
".",
"trace",
"(",
"\"",
"\"",
",",
"ctx",
")",
"\n",
"if",
"ctx",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"ctx",
".",
"IsTrusted",
"(",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"configs",
":=",
"s",
".",
"engine",
".",
"hcManager",
".",
"configs",
"(",
")",
"\n",
"if",
"reply",
"!=",
"nil",
"{",
"reply",
".",
"Configs",
"=",
"configs",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Healthchecks returns a list of currently configured healthchecks that
// should be performed by the Seesaw Healthcheck component. | [
"Healthchecks",
"returns",
"a",
"list",
"of",
"currently",
"configured",
"healthchecks",
"that",
"should",
"be",
"performed",
"by",
"the",
"Seesaw",
"Healthcheck",
"component",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/ipc.go#L149-L164 | train |
google/seesaw | engine/ipc.go | HealthState | func (s *SeesawEngine) HealthState(args *healthcheck.HealthState, reply *int) error {
if args == nil {
return errors.New("args is nil")
}
ctx := args.Ctx
s.trace("HealthState", ctx)
if ctx == nil {
return errors.New("context is nil")
}
if !ctx.IsTrusted() {
return errors.New("insufficient access")
}
for _, n := range args.Notifications {
if err := s.engine.hcManager.healthState(n); err != nil {
return err
}
}
return nil
} | go | func (s *SeesawEngine) HealthState(args *healthcheck.HealthState, reply *int) error {
if args == nil {
return errors.New("args is nil")
}
ctx := args.Ctx
s.trace("HealthState", ctx)
if ctx == nil {
return errors.New("context is nil")
}
if !ctx.IsTrusted() {
return errors.New("insufficient access")
}
for _, n := range args.Notifications {
if err := s.engine.hcManager.healthState(n); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"s",
"*",
"SeesawEngine",
")",
"HealthState",
"(",
"args",
"*",
"healthcheck",
".",
"HealthState",
",",
"reply",
"*",
"int",
")",
"error",
"{",
"if",
"args",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"ctx",
":=",
"args",
".",
"Ctx",
"\n",
"s",
".",
"trace",
"(",
"\"",
"\"",
",",
"ctx",
")",
"\n",
"if",
"ctx",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"ctx",
".",
"IsTrusted",
"(",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"n",
":=",
"range",
"args",
".",
"Notifications",
"{",
"if",
"err",
":=",
"s",
".",
"engine",
".",
"hcManager",
".",
"healthState",
"(",
"n",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // HealthState advises the Seesaw Engine of state transitions for a set of
// healthchecks that are being performed by the Seesaw Healthcheck component. | [
"HealthState",
"advises",
"the",
"Seesaw",
"Engine",
"of",
"state",
"transitions",
"for",
"a",
"set",
"of",
"healthchecks",
"that",
"are",
"being",
"performed",
"by",
"the",
"Seesaw",
"Healthcheck",
"component",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/ipc.go#L168-L189 | train |
google/seesaw | engine/ipc.go | ClusterStatus | func (s *SeesawEngine) ClusterStatus(ctx *ipc.Context, reply *seesaw.ClusterStatus) error {
s.trace("ClusterStatus", ctx)
if ctx == nil {
return errors.New("context is nil")
}
if !ctx.IsTrusted() {
return errors.New("insufficient access")
}
s.engine.clusterLock.RLock()
cluster := s.engine.cluster
s.engine.clusterLock.RUnlock()
if cluster == nil {
return errors.New("no cluster configuration loaded")
}
reply.Version = seesaw.SeesawVersion
reply.Site = cluster.Site
reply.Nodes = make([]*seesaw.Node, 0, len(cluster.Nodes))
for _, node := range cluster.Nodes {
reply.Nodes = append(reply.Nodes, node.Clone())
}
return nil
} | go | func (s *SeesawEngine) ClusterStatus(ctx *ipc.Context, reply *seesaw.ClusterStatus) error {
s.trace("ClusterStatus", ctx)
if ctx == nil {
return errors.New("context is nil")
}
if !ctx.IsTrusted() {
return errors.New("insufficient access")
}
s.engine.clusterLock.RLock()
cluster := s.engine.cluster
s.engine.clusterLock.RUnlock()
if cluster == nil {
return errors.New("no cluster configuration loaded")
}
reply.Version = seesaw.SeesawVersion
reply.Site = cluster.Site
reply.Nodes = make([]*seesaw.Node, 0, len(cluster.Nodes))
for _, node := range cluster.Nodes {
reply.Nodes = append(reply.Nodes, node.Clone())
}
return nil
} | [
"func",
"(",
"s",
"*",
"SeesawEngine",
")",
"ClusterStatus",
"(",
"ctx",
"*",
"ipc",
".",
"Context",
",",
"reply",
"*",
"seesaw",
".",
"ClusterStatus",
")",
"error",
"{",
"s",
".",
"trace",
"(",
"\"",
"\"",
",",
"ctx",
")",
"\n",
"if",
"ctx",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"ctx",
".",
"IsTrusted",
"(",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"s",
".",
"engine",
".",
"clusterLock",
".",
"RLock",
"(",
")",
"\n",
"cluster",
":=",
"s",
".",
"engine",
".",
"cluster",
"\n",
"s",
".",
"engine",
".",
"clusterLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"if",
"cluster",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"reply",
".",
"Version",
"=",
"seesaw",
".",
"SeesawVersion",
"\n",
"reply",
".",
"Site",
"=",
"cluster",
".",
"Site",
"\n",
"reply",
".",
"Nodes",
"=",
"make",
"(",
"[",
"]",
"*",
"seesaw",
".",
"Node",
",",
"0",
",",
"len",
"(",
"cluster",
".",
"Nodes",
")",
")",
"\n",
"for",
"_",
",",
"node",
":=",
"range",
"cluster",
".",
"Nodes",
"{",
"reply",
".",
"Nodes",
"=",
"append",
"(",
"reply",
".",
"Nodes",
",",
"node",
".",
"Clone",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // ClusterStatus returns status information about this Seesaw Cluster. | [
"ClusterStatus",
"returns",
"status",
"information",
"about",
"this",
"Seesaw",
"Cluster",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/ipc.go#L192-L217 | train |
google/seesaw | engine/ipc.go | VLANs | func (s *SeesawEngine) VLANs(ctx *ipc.Context, reply *seesaw.VLANs) error {
s.trace("VLANs", ctx)
if ctx == nil {
return errors.New("context is nil")
}
if !ctx.IsTrusted() {
return errors.New("insufficient access")
}
if reply == nil {
return errors.New("VLANs is nil")
}
reply.VLANs = make([]*seesaw.VLAN, 0)
s.engine.vlanLock.RLock()
for _, vlan := range s.engine.vlans {
reply.VLANs = append(reply.VLANs, vlan)
}
s.engine.vlanLock.RUnlock()
return nil
} | go | func (s *SeesawEngine) VLANs(ctx *ipc.Context, reply *seesaw.VLANs) error {
s.trace("VLANs", ctx)
if ctx == nil {
return errors.New("context is nil")
}
if !ctx.IsTrusted() {
return errors.New("insufficient access")
}
if reply == nil {
return errors.New("VLANs is nil")
}
reply.VLANs = make([]*seesaw.VLAN, 0)
s.engine.vlanLock.RLock()
for _, vlan := range s.engine.vlans {
reply.VLANs = append(reply.VLANs, vlan)
}
s.engine.vlanLock.RUnlock()
return nil
} | [
"func",
"(",
"s",
"*",
"SeesawEngine",
")",
"VLANs",
"(",
"ctx",
"*",
"ipc",
".",
"Context",
",",
"reply",
"*",
"seesaw",
".",
"VLANs",
")",
"error",
"{",
"s",
".",
"trace",
"(",
"\"",
"\"",
",",
"ctx",
")",
"\n",
"if",
"ctx",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"ctx",
".",
"IsTrusted",
"(",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"reply",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"reply",
".",
"VLANs",
"=",
"make",
"(",
"[",
"]",
"*",
"seesaw",
".",
"VLAN",
",",
"0",
")",
"\n",
"s",
".",
"engine",
".",
"vlanLock",
".",
"RLock",
"(",
")",
"\n",
"for",
"_",
",",
"vlan",
":=",
"range",
"s",
".",
"engine",
".",
"vlans",
"{",
"reply",
".",
"VLANs",
"=",
"append",
"(",
"reply",
".",
"VLANs",
",",
"vlan",
")",
"\n",
"}",
"\n",
"s",
".",
"engine",
".",
"vlanLock",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // VLANs returns a list of VLANs configured for this cluster. | [
"VLANs",
"returns",
"a",
"list",
"of",
"VLANs",
"configured",
"for",
"this",
"cluster",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/ipc.go#L318-L338 | train |
google/seesaw | engine/ipc.go | OverrideBackend | func (s *SeesawEngine) OverrideBackend(args *ipc.Override, reply *int) error {
if args == nil {
return errors.New("args is nil")
}
ctx := args.Ctx
s.trace("OverrideBackend", ctx)
if ctx == nil {
return errors.New("context is nil")
}
if !ctx.IsTrusted() {
return errors.New("insufficient access")
}
if args.Backend == nil {
return errors.New("backend is nil")
}
s.engine.queueOverride(args.Backend)
return nil
} | go | func (s *SeesawEngine) OverrideBackend(args *ipc.Override, reply *int) error {
if args == nil {
return errors.New("args is nil")
}
ctx := args.Ctx
s.trace("OverrideBackend", ctx)
if ctx == nil {
return errors.New("context is nil")
}
if !ctx.IsTrusted() {
return errors.New("insufficient access")
}
if args.Backend == nil {
return errors.New("backend is nil")
}
s.engine.queueOverride(args.Backend)
return nil
} | [
"func",
"(",
"s",
"*",
"SeesawEngine",
")",
"OverrideBackend",
"(",
"args",
"*",
"ipc",
".",
"Override",
",",
"reply",
"*",
"int",
")",
"error",
"{",
"if",
"args",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"ctx",
":=",
"args",
".",
"Ctx",
"\n",
"s",
".",
"trace",
"(",
"\"",
"\"",
",",
"ctx",
")",
"\n",
"if",
"ctx",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"ctx",
".",
"IsTrusted",
"(",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"args",
".",
"Backend",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"s",
".",
"engine",
".",
"queueOverride",
"(",
"args",
".",
"Backend",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // OverrideBackend passes a BackendOverride to the engine. | [
"OverrideBackend",
"passes",
"a",
"BackendOverride",
"to",
"the",
"engine",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/ipc.go#L364-L383 | train |
google/seesaw | common/conn/rpc.go | ClusterStatus | func (c *engineRPC) ClusterStatus() (*seesaw.ClusterStatus, error) {
var cs seesaw.ClusterStatus
if err := c.client.Call("SeesawECU.ClusterStatus", c.ctx, &cs); err != nil {
return nil, err
}
return &cs, nil
} | go | func (c *engineRPC) ClusterStatus() (*seesaw.ClusterStatus, error) {
var cs seesaw.ClusterStatus
if err := c.client.Call("SeesawECU.ClusterStatus", c.ctx, &cs); err != nil {
return nil, err
}
return &cs, nil
} | [
"func",
"(",
"c",
"*",
"engineRPC",
")",
"ClusterStatus",
"(",
")",
"(",
"*",
"seesaw",
".",
"ClusterStatus",
",",
"error",
")",
"{",
"var",
"cs",
"seesaw",
".",
"ClusterStatus",
"\n",
"if",
"err",
":=",
"c",
".",
"client",
".",
"Call",
"(",
"\"",
"\"",
",",
"c",
".",
"ctx",
",",
"&",
"cs",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"cs",
",",
"nil",
"\n",
"}"
] | // ClusterStatus requests the status of the Seesaw Cluster. | [
"ClusterStatus",
"requests",
"the",
"status",
"of",
"the",
"Seesaw",
"Cluster",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/conn/rpc.go#L77-L83 | train |
google/seesaw | common/conn/rpc.go | Backends | func (c *engineRPC) Backends() (map[string]*seesaw.Backend, error) {
var bm seesaw.BackendMap
if err := c.client.Call("SeesawECU.Backends", c.ctx, &bm); err != nil {
return nil, err
}
return bm.Backends, nil
} | go | func (c *engineRPC) Backends() (map[string]*seesaw.Backend, error) {
var bm seesaw.BackendMap
if err := c.client.Call("SeesawECU.Backends", c.ctx, &bm); err != nil {
return nil, err
}
return bm.Backends, nil
} | [
"func",
"(",
"c",
"*",
"engineRPC",
")",
"Backends",
"(",
")",
"(",
"map",
"[",
"string",
"]",
"*",
"seesaw",
".",
"Backend",
",",
"error",
")",
"{",
"var",
"bm",
"seesaw",
".",
"BackendMap",
"\n",
"if",
"err",
":=",
"c",
".",
"client",
".",
"Call",
"(",
"\"",
"\"",
",",
"c",
".",
"ctx",
",",
"&",
"bm",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"bm",
".",
"Backends",
",",
"nil",
"\n",
"}"
] | // Backends requests a list of all backends that are configured on the cluster. | [
"Backends",
"requests",
"a",
"list",
"of",
"all",
"backends",
"that",
"are",
"configured",
"on",
"the",
"cluster",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/conn/rpc.go#L148-L154 | train |
google/seesaw | common/conn/rpc.go | OverrideBackend | func (c *engineRPC) OverrideBackend(backend *seesaw.BackendOverride) error {
override := &ipc.Override{Ctx: c.ctx, Backend: backend}
return c.client.Call("SeesawECU.OverrideBackend", override, nil)
} | go | func (c *engineRPC) OverrideBackend(backend *seesaw.BackendOverride) error {
override := &ipc.Override{Ctx: c.ctx, Backend: backend}
return c.client.Call("SeesawECU.OverrideBackend", override, nil)
} | [
"func",
"(",
"c",
"*",
"engineRPC",
")",
"OverrideBackend",
"(",
"backend",
"*",
"seesaw",
".",
"BackendOverride",
")",
"error",
"{",
"override",
":=",
"&",
"ipc",
".",
"Override",
"{",
"Ctx",
":",
"c",
".",
"ctx",
",",
"Backend",
":",
"backend",
"}",
"\n",
"return",
"c",
".",
"client",
".",
"Call",
"(",
"\"",
"\"",
",",
"override",
",",
"nil",
")",
"\n",
"}"
] | // OverrideBackend requests that the specified VserverOverride be applied. | [
"OverrideBackend",
"requests",
"that",
"the",
"specified",
"VserverOverride",
"be",
"applied",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/conn/rpc.go#L157-L160 | train |
google/seesaw | healthcheck/ping.go | NewPingChecker | func NewPingChecker(ip net.IP) *PingChecker {
proto := seesaw.IPProtoICMP
if ip.To4() == nil {
proto = seesaw.IPProtoICMPv6
}
id := nextPingCheckerID
nextPingCheckerID++
return &PingChecker{
Target: Target{
IP: ip,
Proto: proto,
},
ID: id,
}
} | go | func NewPingChecker(ip net.IP) *PingChecker {
proto := seesaw.IPProtoICMP
if ip.To4() == nil {
proto = seesaw.IPProtoICMPv6
}
id := nextPingCheckerID
nextPingCheckerID++
return &PingChecker{
Target: Target{
IP: ip,
Proto: proto,
},
ID: id,
}
} | [
"func",
"NewPingChecker",
"(",
"ip",
"net",
".",
"IP",
")",
"*",
"PingChecker",
"{",
"proto",
":=",
"seesaw",
".",
"IPProtoICMP",
"\n",
"if",
"ip",
".",
"To4",
"(",
")",
"==",
"nil",
"{",
"proto",
"=",
"seesaw",
".",
"IPProtoICMPv6",
"\n",
"}",
"\n",
"id",
":=",
"nextPingCheckerID",
"\n",
"nextPingCheckerID",
"++",
"\n",
"return",
"&",
"PingChecker",
"{",
"Target",
":",
"Target",
"{",
"IP",
":",
"ip",
",",
"Proto",
":",
"proto",
",",
"}",
",",
"ID",
":",
"id",
",",
"}",
"\n",
"}"
] | // NewPingChecker returns an initialised PingChecker. | [
"NewPingChecker",
"returns",
"an",
"initialised",
"PingChecker",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/ping.go#L51-L65 | train |
google/seesaw | healthcheck/ping.go | Check | func (hc *PingChecker) Check(timeout time.Duration) *Result {
msg := fmt.Sprintf("ICMP ping to host %v", hc.IP)
seq := hc.Seqnum
hc.Seqnum++
echo := newICMPEchoRequest(hc.Proto, hc.ID, seq, 64, []byte("Healthcheck"))
start := time.Now()
if timeout == time.Duration(0) {
timeout = defaultPingTimeout
}
err := exchangeICMPEcho(hc.network(), hc.IP, timeout, echo)
success := err == nil
return complete(start, msg, success, err)
} | go | func (hc *PingChecker) Check(timeout time.Duration) *Result {
msg := fmt.Sprintf("ICMP ping to host %v", hc.IP)
seq := hc.Seqnum
hc.Seqnum++
echo := newICMPEchoRequest(hc.Proto, hc.ID, seq, 64, []byte("Healthcheck"))
start := time.Now()
if timeout == time.Duration(0) {
timeout = defaultPingTimeout
}
err := exchangeICMPEcho(hc.network(), hc.IP, timeout, echo)
success := err == nil
return complete(start, msg, success, err)
} | [
"func",
"(",
"hc",
"*",
"PingChecker",
")",
"Check",
"(",
"timeout",
"time",
".",
"Duration",
")",
"*",
"Result",
"{",
"msg",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"hc",
".",
"IP",
")",
"\n",
"seq",
":=",
"hc",
".",
"Seqnum",
"\n",
"hc",
".",
"Seqnum",
"++",
"\n",
"echo",
":=",
"newICMPEchoRequest",
"(",
"hc",
".",
"Proto",
",",
"hc",
".",
"ID",
",",
"seq",
",",
"64",
",",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
")",
"\n",
"start",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"if",
"timeout",
"==",
"time",
".",
"Duration",
"(",
"0",
")",
"{",
"timeout",
"=",
"defaultPingTimeout",
"\n",
"}",
"\n",
"err",
":=",
"exchangeICMPEcho",
"(",
"hc",
".",
"network",
"(",
")",
",",
"hc",
".",
"IP",
",",
"timeout",
",",
"echo",
")",
"\n",
"success",
":=",
"err",
"==",
"nil",
"\n",
"return",
"complete",
"(",
"start",
",",
"msg",
",",
"success",
",",
"err",
")",
"\n",
"}"
] | // Check executes a ping healthcheck. | [
"Check",
"executes",
"a",
"ping",
"healthcheck",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/ping.go#L73-L85 | train |
google/seesaw | ha/net.go | NewIPHAConn | func NewIPHAConn(laddr, raddr net.IP) (HAConn, error) {
sendConn, err := IPConn(laddr, raddr)
if err != nil {
return nil, err
}
// For IPv6 unicast and multicast, and for IPv4 unicast, we can use the same IPConn for both
// sending and receiving. For IPv4 multicast, we need a separate listener for receiving.
recvConn := sendConn
if raddr.IsMulticast() {
if raddr.To4() != nil {
log.Infof("Using IPv4 multicast")
if recvConn, err = ListenMulticastIPv4(raddr, laddr); err != nil {
return nil, err
}
} else {
log.Infof("Using IPv6 multicast")
if err = JoinMulticastIPv6(recvConn, raddr, laddr); err != nil {
return nil, err
}
}
}
return &IPHAConn{
sendConn: sendConn,
recvConn: recvConn,
laddr: laddr,
raddr: raddr,
}, nil
} | go | func NewIPHAConn(laddr, raddr net.IP) (HAConn, error) {
sendConn, err := IPConn(laddr, raddr)
if err != nil {
return nil, err
}
// For IPv6 unicast and multicast, and for IPv4 unicast, we can use the same IPConn for both
// sending and receiving. For IPv4 multicast, we need a separate listener for receiving.
recvConn := sendConn
if raddr.IsMulticast() {
if raddr.To4() != nil {
log.Infof("Using IPv4 multicast")
if recvConn, err = ListenMulticastIPv4(raddr, laddr); err != nil {
return nil, err
}
} else {
log.Infof("Using IPv6 multicast")
if err = JoinMulticastIPv6(recvConn, raddr, laddr); err != nil {
return nil, err
}
}
}
return &IPHAConn{
sendConn: sendConn,
recvConn: recvConn,
laddr: laddr,
raddr: raddr,
}, nil
} | [
"func",
"NewIPHAConn",
"(",
"laddr",
",",
"raddr",
"net",
".",
"IP",
")",
"(",
"HAConn",
",",
"error",
")",
"{",
"sendConn",
",",
"err",
":=",
"IPConn",
"(",
"laddr",
",",
"raddr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// For IPv6 unicast and multicast, and for IPv4 unicast, we can use the same IPConn for both",
"// sending and receiving. For IPv4 multicast, we need a separate listener for receiving.",
"recvConn",
":=",
"sendConn",
"\n",
"if",
"raddr",
".",
"IsMulticast",
"(",
")",
"{",
"if",
"raddr",
".",
"To4",
"(",
")",
"!=",
"nil",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"if",
"recvConn",
",",
"err",
"=",
"ListenMulticastIPv4",
"(",
"raddr",
",",
"laddr",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"else",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"=",
"JoinMulticastIPv6",
"(",
"recvConn",
",",
"raddr",
",",
"laddr",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"&",
"IPHAConn",
"{",
"sendConn",
":",
"sendConn",
",",
"recvConn",
":",
"recvConn",
",",
"laddr",
":",
"laddr",
",",
"raddr",
":",
"raddr",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewIPHAConn creates a new IPHAConn. | [
"NewIPHAConn",
"creates",
"a",
"new",
"IPHAConn",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ha/net.go#L143-L172 | train |
google/seesaw | ha/net.go | ListenMulticastIPv4 | func ListenMulticastIPv4(gaddr, laddr net.IP) (*net.IPConn, error) {
gaddr = gaddr.To4()
laddr = laddr.To4()
c, err := net.ListenIP("ip4:112", &net.IPAddr{IP: gaddr})
if err != nil {
return nil, err
}
f, err := c.File()
if err != nil {
return nil, err
}
defer f.Close()
mreq := &syscall.IPMreq{
Multiaddr: [4]byte{gaddr[0], gaddr[1], gaddr[2], gaddr[3]},
Interface: [4]byte{laddr[0], laddr[1], laddr[2], laddr[3]},
}
err = syscall.SetsockoptIPMreq(int(f.Fd()), syscall.IPPROTO_IP, syscall.IP_ADD_MEMBERSHIP, mreq)
if err != nil {
return nil, err
}
return c, nil
} | go | func ListenMulticastIPv4(gaddr, laddr net.IP) (*net.IPConn, error) {
gaddr = gaddr.To4()
laddr = laddr.To4()
c, err := net.ListenIP("ip4:112", &net.IPAddr{IP: gaddr})
if err != nil {
return nil, err
}
f, err := c.File()
if err != nil {
return nil, err
}
defer f.Close()
mreq := &syscall.IPMreq{
Multiaddr: [4]byte{gaddr[0], gaddr[1], gaddr[2], gaddr[3]},
Interface: [4]byte{laddr[0], laddr[1], laddr[2], laddr[3]},
}
err = syscall.SetsockoptIPMreq(int(f.Fd()), syscall.IPPROTO_IP, syscall.IP_ADD_MEMBERSHIP, mreq)
if err != nil {
return nil, err
}
return c, nil
} | [
"func",
"ListenMulticastIPv4",
"(",
"gaddr",
",",
"laddr",
"net",
".",
"IP",
")",
"(",
"*",
"net",
".",
"IPConn",
",",
"error",
")",
"{",
"gaddr",
"=",
"gaddr",
".",
"To4",
"(",
")",
"\n",
"laddr",
"=",
"laddr",
".",
"To4",
"(",
")",
"\n",
"c",
",",
"err",
":=",
"net",
".",
"ListenIP",
"(",
"\"",
"\"",
",",
"&",
"net",
".",
"IPAddr",
"{",
"IP",
":",
"gaddr",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"f",
",",
"err",
":=",
"c",
".",
"File",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n\n",
"mreq",
":=",
"&",
"syscall",
".",
"IPMreq",
"{",
"Multiaddr",
":",
"[",
"4",
"]",
"byte",
"{",
"gaddr",
"[",
"0",
"]",
",",
"gaddr",
"[",
"1",
"]",
",",
"gaddr",
"[",
"2",
"]",
",",
"gaddr",
"[",
"3",
"]",
"}",
",",
"Interface",
":",
"[",
"4",
"]",
"byte",
"{",
"laddr",
"[",
"0",
"]",
",",
"laddr",
"[",
"1",
"]",
",",
"laddr",
"[",
"2",
"]",
",",
"laddr",
"[",
"3",
"]",
"}",
",",
"}",
"\n\n",
"err",
"=",
"syscall",
".",
"SetsockoptIPMreq",
"(",
"int",
"(",
"f",
".",
"Fd",
"(",
")",
")",
",",
"syscall",
".",
"IPPROTO_IP",
",",
"syscall",
".",
"IP_ADD_MEMBERSHIP",
",",
"mreq",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"c",
",",
"nil",
"\n",
"}"
] | // ListenMulticastIPv4 creates a net.IPConn to receive multicast messages for the given group
// address. laddr specifies which network interface to use when joining the group. | [
"ListenMulticastIPv4",
"creates",
"a",
"net",
".",
"IPConn",
"to",
"receive",
"multicast",
"messages",
"for",
"the",
"given",
"group",
"address",
".",
"laddr",
"specifies",
"which",
"network",
"interface",
"to",
"use",
"when",
"joining",
"the",
"group",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ha/net.go#L176-L201 | train |
google/seesaw | ha/net.go | JoinMulticastIPv6 | func JoinMulticastIPv6(c *net.IPConn, gaddr, laddr net.IP) error {
f, err := c.File()
if err != nil {
return err
}
defer f.Close()
mreq := &syscall.IPv6Mreq{}
copy(mreq.Multiaddr[:], gaddr.To16())
iface, err := findInterface(laddr)
if err != nil {
return err
}
mreq.Interface = uint32(iface.Index)
err = syscall.SetsockoptIPv6Mreq(int(f.Fd()), syscall.IPPROTO_IPV6, syscall.IPV6_JOIN_GROUP, mreq)
if err != nil {
return err
}
return nil
} | go | func JoinMulticastIPv6(c *net.IPConn, gaddr, laddr net.IP) error {
f, err := c.File()
if err != nil {
return err
}
defer f.Close()
mreq := &syscall.IPv6Mreq{}
copy(mreq.Multiaddr[:], gaddr.To16())
iface, err := findInterface(laddr)
if err != nil {
return err
}
mreq.Interface = uint32(iface.Index)
err = syscall.SetsockoptIPv6Mreq(int(f.Fd()), syscall.IPPROTO_IPV6, syscall.IPV6_JOIN_GROUP, mreq)
if err != nil {
return err
}
return nil
} | [
"func",
"JoinMulticastIPv6",
"(",
"c",
"*",
"net",
".",
"IPConn",
",",
"gaddr",
",",
"laddr",
"net",
".",
"IP",
")",
"error",
"{",
"f",
",",
"err",
":=",
"c",
".",
"File",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n\n",
"mreq",
":=",
"&",
"syscall",
".",
"IPv6Mreq",
"{",
"}",
"\n",
"copy",
"(",
"mreq",
".",
"Multiaddr",
"[",
":",
"]",
",",
"gaddr",
".",
"To16",
"(",
")",
")",
"\n",
"iface",
",",
"err",
":=",
"findInterface",
"(",
"laddr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"mreq",
".",
"Interface",
"=",
"uint32",
"(",
"iface",
".",
"Index",
")",
"\n\n",
"err",
"=",
"syscall",
".",
"SetsockoptIPv6Mreq",
"(",
"int",
"(",
"f",
".",
"Fd",
"(",
")",
")",
",",
"syscall",
".",
"IPPROTO_IPV6",
",",
"syscall",
".",
"IPV6_JOIN_GROUP",
",",
"mreq",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // JoinMulticastIPv6 joins the multicast group address given by gaddr. laddr specifies which
// network interface to use when joining the group. | [
"JoinMulticastIPv6",
"joins",
"the",
"multicast",
"group",
"address",
"given",
"by",
"gaddr",
".",
"laddr",
"specifies",
"which",
"network",
"interface",
"to",
"use",
"when",
"joining",
"the",
"group",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ha/net.go#L205-L225 | train |
google/seesaw | ha/net.go | af | func (c *IPHAConn) af() int {
if c.laddr.To4() != nil {
return syscall.AF_INET
}
return syscall.AF_INET6
} | go | func (c *IPHAConn) af() int {
if c.laddr.To4() != nil {
return syscall.AF_INET
}
return syscall.AF_INET6
} | [
"func",
"(",
"c",
"*",
"IPHAConn",
")",
"af",
"(",
")",
"int",
"{",
"if",
"c",
".",
"laddr",
".",
"To4",
"(",
")",
"!=",
"nil",
"{",
"return",
"syscall",
".",
"AF_INET",
"\n",
"}",
"\n",
"return",
"syscall",
".",
"AF_INET6",
"\n",
"}"
] | // af returns the address family for an IPHAConn. | [
"af",
"returns",
"the",
"address",
"family",
"for",
"an",
"IPHAConn",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ha/net.go#L248-L253 | train |
google/seesaw | ha/net.go | readPacket | func (c *IPHAConn) readPacket() (*packet, error) {
switch c.af() {
case syscall.AF_INET:
return c.readIPv4Packet()
case syscall.AF_INET6:
return c.readIPv6Packet()
}
panic("unreachable")
} | go | func (c *IPHAConn) readPacket() (*packet, error) {
switch c.af() {
case syscall.AF_INET:
return c.readIPv4Packet()
case syscall.AF_INET6:
return c.readIPv6Packet()
}
panic("unreachable")
} | [
"func",
"(",
"c",
"*",
"IPHAConn",
")",
"readPacket",
"(",
")",
"(",
"*",
"packet",
",",
"error",
")",
"{",
"switch",
"c",
".",
"af",
"(",
")",
"{",
"case",
"syscall",
".",
"AF_INET",
":",
"return",
"c",
".",
"readIPv4Packet",
"(",
")",
"\n",
"case",
"syscall",
".",
"AF_INET6",
":",
"return",
"c",
".",
"readIPv6Packet",
"(",
")",
"\n",
"}",
"\n",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // readPacket reads a packet from this IPHAConn's recvConn. | [
"readPacket",
"reads",
"a",
"packet",
"from",
"this",
"IPHAConn",
"s",
"recvConn",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ha/net.go#L329-L337 | train |
google/seesaw | watchdog/core.go | NewWatchdog | func NewWatchdog() *Watchdog {
return &Watchdog{
services: make(map[string]*Service),
shutdown: make(chan bool),
}
} | go | func NewWatchdog() *Watchdog {
return &Watchdog{
services: make(map[string]*Service),
shutdown: make(chan bool),
}
} | [
"func",
"NewWatchdog",
"(",
")",
"*",
"Watchdog",
"{",
"return",
"&",
"Watchdog",
"{",
"services",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"Service",
")",
",",
"shutdown",
":",
"make",
"(",
"chan",
"bool",
")",
",",
"}",
"\n",
"}"
] | // NewWatchdog returns an initialised watchdog. | [
"NewWatchdog",
"returns",
"an",
"initialised",
"watchdog",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/watchdog/core.go#L37-L42 | train |
google/seesaw | watchdog/core.go | AddService | func (w *Watchdog) AddService(name, binary string) (*Service, error) {
if _, ok := w.services[name]; ok {
return nil, fmt.Errorf("Service %q already exists", name)
}
svc := newService(name, binary)
w.services[name] = svc
return svc, nil
} | go | func (w *Watchdog) AddService(name, binary string) (*Service, error) {
if _, ok := w.services[name]; ok {
return nil, fmt.Errorf("Service %q already exists", name)
}
svc := newService(name, binary)
w.services[name] = svc
return svc, nil
} | [
"func",
"(",
"w",
"*",
"Watchdog",
")",
"AddService",
"(",
"name",
",",
"binary",
"string",
")",
"(",
"*",
"Service",
",",
"error",
")",
"{",
"if",
"_",
",",
"ok",
":=",
"w",
".",
"services",
"[",
"name",
"]",
";",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n\n",
"svc",
":=",
"newService",
"(",
"name",
",",
"binary",
")",
"\n",
"w",
".",
"services",
"[",
"name",
"]",
"=",
"svc",
"\n\n",
"return",
"svc",
",",
"nil",
"\n",
"}"
] | // AddService adds a service that is to be run by the watchdog. | [
"AddService",
"adds",
"a",
"service",
"that",
"is",
"to",
"be",
"run",
"by",
"the",
"watchdog",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/watchdog/core.go#L53-L62 | train |
google/seesaw | watchdog/core.go | Walk | func (w *Watchdog) Walk() {
log.Info("Seesaw watchdog starting...")
w.mapDependencies()
for _, svc := range w.services {
go svc.run()
}
<-w.shutdown
for _, svc := range w.services {
go svc.stop()
}
for _, svc := range w.services {
stopped := <-svc.stopped
svc.stopped <- stopped
}
} | go | func (w *Watchdog) Walk() {
log.Info("Seesaw watchdog starting...")
w.mapDependencies()
for _, svc := range w.services {
go svc.run()
}
<-w.shutdown
for _, svc := range w.services {
go svc.stop()
}
for _, svc := range w.services {
stopped := <-svc.stopped
svc.stopped <- stopped
}
} | [
"func",
"(",
"w",
"*",
"Watchdog",
")",
"Walk",
"(",
")",
"{",
"log",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n\n",
"w",
".",
"mapDependencies",
"(",
")",
"\n\n",
"for",
"_",
",",
"svc",
":=",
"range",
"w",
".",
"services",
"{",
"go",
"svc",
".",
"run",
"(",
")",
"\n",
"}",
"\n",
"<-",
"w",
".",
"shutdown",
"\n",
"for",
"_",
",",
"svc",
":=",
"range",
"w",
".",
"services",
"{",
"go",
"svc",
".",
"stop",
"(",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"svc",
":=",
"range",
"w",
".",
"services",
"{",
"stopped",
":=",
"<-",
"svc",
".",
"stopped",
"\n",
"svc",
".",
"stopped",
"<-",
"stopped",
"\n",
"}",
"\n",
"}"
] | // Walk takes the watchdog component for a walk so that it can run the
// configured services. | [
"Walk",
"takes",
"the",
"watchdog",
"component",
"for",
"a",
"walk",
"so",
"that",
"it",
"can",
"run",
"the",
"configured",
"services",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/watchdog/core.go#L66-L82 | train |
google/seesaw | watchdog/core.go | mapDependencies | func (w *Watchdog) mapDependencies() {
for name := range w.services {
svc := w.services[name]
for depName := range svc.dependencies {
dep, ok := w.services[depName]
if !ok {
log.Fatalf("Failed to find dependency %q for service %q", depName, name)
}
svc.dependencies[depName] = dep
dep.dependents[svc.name] = svc
}
}
} | go | func (w *Watchdog) mapDependencies() {
for name := range w.services {
svc := w.services[name]
for depName := range svc.dependencies {
dep, ok := w.services[depName]
if !ok {
log.Fatalf("Failed to find dependency %q for service %q", depName, name)
}
svc.dependencies[depName] = dep
dep.dependents[svc.name] = svc
}
}
} | [
"func",
"(",
"w",
"*",
"Watchdog",
")",
"mapDependencies",
"(",
")",
"{",
"for",
"name",
":=",
"range",
"w",
".",
"services",
"{",
"svc",
":=",
"w",
".",
"services",
"[",
"name",
"]",
"\n",
"for",
"depName",
":=",
"range",
"svc",
".",
"dependencies",
"{",
"dep",
",",
"ok",
":=",
"w",
".",
"services",
"[",
"depName",
"]",
"\n",
"if",
"!",
"ok",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"depName",
",",
"name",
")",
"\n",
"}",
"\n",
"svc",
".",
"dependencies",
"[",
"depName",
"]",
"=",
"dep",
"\n",
"dep",
".",
"dependents",
"[",
"svc",
".",
"name",
"]",
"=",
"svc",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // mapDependencies maps service dependency names to configured services. | [
"mapDependencies",
"maps",
"service",
"dependency",
"names",
"to",
"configured",
"services",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/watchdog/core.go#L85-L97 | train |
google/seesaw | ecu/control.go | VLANs | func (s *SeesawECU) VLANs(ctx *ipc.Context, reply *seesaw.VLANs) error {
s.trace("VLANs", ctx)
authConn, err := s.ecu.authConnect(ctx)
if err != nil {
return err
}
defer authConn.Close()
vlans, err := authConn.VLANs()
if err != nil {
return err
}
if reply != nil {
*reply = *vlans
}
return nil
} | go | func (s *SeesawECU) VLANs(ctx *ipc.Context, reply *seesaw.VLANs) error {
s.trace("VLANs", ctx)
authConn, err := s.ecu.authConnect(ctx)
if err != nil {
return err
}
defer authConn.Close()
vlans, err := authConn.VLANs()
if err != nil {
return err
}
if reply != nil {
*reply = *vlans
}
return nil
} | [
"func",
"(",
"s",
"*",
"SeesawECU",
")",
"VLANs",
"(",
"ctx",
"*",
"ipc",
".",
"Context",
",",
"reply",
"*",
"seesaw",
".",
"VLANs",
")",
"error",
"{",
"s",
".",
"trace",
"(",
"\"",
"\"",
",",
"ctx",
")",
"\n\n",
"authConn",
",",
"err",
":=",
"s",
".",
"ecu",
".",
"authConnect",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"authConn",
".",
"Close",
"(",
")",
"\n\n",
"vlans",
",",
"err",
":=",
"authConn",
".",
"VLANs",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"reply",
"!=",
"nil",
"{",
"*",
"reply",
"=",
"*",
"vlans",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // VLANs returns a list of currently configured VLANs. | [
"VLANs",
"returns",
"a",
"list",
"of",
"currently",
"configured",
"VLANs",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ecu/control.go#L184-L202 | train |
google/seesaw | healthcheck/dns.go | DNSType | func DNSType(name string) (uint16, error) {
dt, ok := dns.StringToType[strings.ToUpper(name)]
if !ok {
return 0, fmt.Errorf("unknown DNS type %q", name)
}
return dt, nil
} | go | func DNSType(name string) (uint16, error) {
dt, ok := dns.StringToType[strings.ToUpper(name)]
if !ok {
return 0, fmt.Errorf("unknown DNS type %q", name)
}
return dt, nil
} | [
"func",
"DNSType",
"(",
"name",
"string",
")",
"(",
"uint16",
",",
"error",
")",
"{",
"dt",
",",
"ok",
":=",
"dns",
".",
"StringToType",
"[",
"strings",
".",
"ToUpper",
"(",
"name",
")",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"return",
"dt",
",",
"nil",
"\n",
"}"
] | // DNSType returns the dnsType that corresponds with the given name. | [
"DNSType",
"returns",
"the",
"dnsType",
"that",
"corresponds",
"with",
"the",
"given",
"name",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/dns.go#L37-L43 | train |
google/seesaw | healthcheck/dns.go | NewDNSChecker | func NewDNSChecker(ip net.IP, port int) *DNSChecker {
return &DNSChecker{
Target: Target{
IP: ip,
Port: port,
Proto: seesaw.IPProtoUDP,
},
Question: dns.Question{
Qclass: dns.ClassINET,
Qtype: dns.TypeA,
},
}
} | go | func NewDNSChecker(ip net.IP, port int) *DNSChecker {
return &DNSChecker{
Target: Target{
IP: ip,
Port: port,
Proto: seesaw.IPProtoUDP,
},
Question: dns.Question{
Qclass: dns.ClassINET,
Qtype: dns.TypeA,
},
}
} | [
"func",
"NewDNSChecker",
"(",
"ip",
"net",
".",
"IP",
",",
"port",
"int",
")",
"*",
"DNSChecker",
"{",
"return",
"&",
"DNSChecker",
"{",
"Target",
":",
"Target",
"{",
"IP",
":",
"ip",
",",
"Port",
":",
"port",
",",
"Proto",
":",
"seesaw",
".",
"IPProtoUDP",
",",
"}",
",",
"Question",
":",
"dns",
".",
"Question",
"{",
"Qclass",
":",
"dns",
".",
"ClassINET",
",",
"Qtype",
":",
"dns",
".",
"TypeA",
",",
"}",
",",
"}",
"\n",
"}"
] | // NewDNSChecker returns an initialised DNSChecker. | [
"NewDNSChecker",
"returns",
"an",
"initialised",
"DNSChecker",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/dns.go#L53-L65 | train |
google/seesaw | healthcheck/dns.go | String | func (hc *DNSChecker) String() string {
return fmt.Sprintf("DNS %s %s", questionToString(hc.Question), hc.Target)
} | go | func (hc *DNSChecker) String() string {
return fmt.Sprintf("DNS %s %s", questionToString(hc.Question), hc.Target)
} | [
"func",
"(",
"hc",
"*",
"DNSChecker",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"questionToString",
"(",
"hc",
".",
"Question",
")",
",",
"hc",
".",
"Target",
")",
"\n",
"}"
] | // String returns the string representation of a DNS healthcheck. | [
"String",
"returns",
"the",
"string",
"representation",
"of",
"a",
"DNS",
"healthcheck",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/dns.go#L72-L74 | train |
google/seesaw | quagga/vty.go | NewVTY | func NewVTY(socket string) *VTY {
return &VTY{
socket: socket,
readTimeout: 1 * time.Second,
writeTimeout: 1 * time.Second,
}
} | go | func NewVTY(socket string) *VTY {
return &VTY{
socket: socket,
readTimeout: 1 * time.Second,
writeTimeout: 1 * time.Second,
}
} | [
"func",
"NewVTY",
"(",
"socket",
"string",
")",
"*",
"VTY",
"{",
"return",
"&",
"VTY",
"{",
"socket",
":",
"socket",
",",
"readTimeout",
":",
"1",
"*",
"time",
".",
"Second",
",",
"writeTimeout",
":",
"1",
"*",
"time",
".",
"Second",
",",
"}",
"\n",
"}"
] | // NewVTY returns an initialised VTY struct. | [
"NewVTY",
"returns",
"an",
"initialised",
"VTY",
"struct",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/quagga/vty.go#L49-L55 | train |
google/seesaw | quagga/vty.go | Dial | func (v *VTY) Dial() error {
if v.conn != nil {
return fmt.Errorf("connection already established")
}
conn, err := net.Dial("unix", v.socket)
if err != nil {
return err
}
v.conn = conn
return nil
} | go | func (v *VTY) Dial() error {
if v.conn != nil {
return fmt.Errorf("connection already established")
}
conn, err := net.Dial("unix", v.socket)
if err != nil {
return err
}
v.conn = conn
return nil
} | [
"func",
"(",
"v",
"*",
"VTY",
")",
"Dial",
"(",
")",
"error",
"{",
"if",
"v",
".",
"conn",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"conn",
",",
"err",
":=",
"net",
".",
"Dial",
"(",
"\"",
"\"",
",",
"v",
".",
"socket",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"v",
".",
"conn",
"=",
"conn",
"\n",
"return",
"nil",
"\n",
"}"
] | // Dial establishes a connection to a Quagga VTY socket. | [
"Dial",
"establishes",
"a",
"connection",
"to",
"a",
"Quagga",
"VTY",
"socket",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/quagga/vty.go#L58-L68 | train |
google/seesaw | quagga/vty.go | Close | func (v *VTY) Close() error {
if v.conn == nil {
return fmt.Errorf("No connection established")
}
err := v.conn.Close()
v.conn = nil
return err
} | go | func (v *VTY) Close() error {
if v.conn == nil {
return fmt.Errorf("No connection established")
}
err := v.conn.Close()
v.conn = nil
return err
} | [
"func",
"(",
"v",
"*",
"VTY",
")",
"Close",
"(",
")",
"error",
"{",
"if",
"v",
".",
"conn",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"err",
":=",
"v",
".",
"conn",
".",
"Close",
"(",
")",
"\n",
"v",
".",
"conn",
"=",
"nil",
"\n",
"return",
"err",
"\n",
"}"
] | // Close closes a connection to a Quagga VTY socket. | [
"Close",
"closes",
"a",
"connection",
"to",
"a",
"Quagga",
"VTY",
"socket",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/quagga/vty.go#L71-L78 | train |
google/seesaw | quagga/vty.go | Commands | func (v *VTY) Commands(cmds []string) error {
for _, cmd := range cmds {
if _, err := v.Command(cmd); err != nil {
return err
}
}
return nil
} | go | func (v *VTY) Commands(cmds []string) error {
for _, cmd := range cmds {
if _, err := v.Command(cmd); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"v",
"*",
"VTY",
")",
"Commands",
"(",
"cmds",
"[",
"]",
"string",
")",
"error",
"{",
"for",
"_",
",",
"cmd",
":=",
"range",
"cmds",
"{",
"if",
"_",
",",
"err",
":=",
"v",
".",
"Command",
"(",
"cmd",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Commands issues a sequence of commands over the Quagga VTY, discarding
// responses. | [
"Commands",
"issues",
"a",
"sequence",
"of",
"commands",
"over",
"the",
"Quagga",
"VTY",
"discarding",
"responses",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/quagga/vty.go#L82-L89 | train |
google/seesaw | quagga/vty.go | Command | func (v *VTY) Command(cmd string) (string, error) {
if err := v.write(cmd); err != nil {
return "", err
}
r, s, err := v.read()
if err != nil {
return "", err
}
if s != 0 {
return "", VTYError{r, s}
}
return r, nil
} | go | func (v *VTY) Command(cmd string) (string, error) {
if err := v.write(cmd); err != nil {
return "", err
}
r, s, err := v.read()
if err != nil {
return "", err
}
if s != 0 {
return "", VTYError{r, s}
}
return r, nil
} | [
"func",
"(",
"v",
"*",
"VTY",
")",
"Command",
"(",
"cmd",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"err",
":=",
"v",
".",
"write",
"(",
"cmd",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"r",
",",
"s",
",",
"err",
":=",
"v",
".",
"read",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"s",
"!=",
"0",
"{",
"return",
"\"",
"\"",
",",
"VTYError",
"{",
"r",
",",
"s",
"}",
"\n",
"}",
"\n",
"return",
"r",
",",
"nil",
"\n",
"}"
] | // Command issues the given command over the Quagga VTY and reads the response. | [
"Command",
"issues",
"the",
"given",
"command",
"over",
"the",
"Quagga",
"VTY",
"and",
"reads",
"the",
"response",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/quagga/vty.go#L92-L104 | train |
google/seesaw | common/ipc/ipc.go | String | func (at AuthType) String() string {
if name, ok := authTypeNames[at]; ok {
return name
}
return "(unknown)"
} | go | func (at AuthType) String() string {
if name, ok := authTypeNames[at]; ok {
return name
}
return "(unknown)"
} | [
"func",
"(",
"at",
"AuthType",
")",
"String",
"(",
")",
"string",
"{",
"if",
"name",
",",
"ok",
":=",
"authTypeNames",
"[",
"at",
"]",
";",
"ok",
"{",
"return",
"name",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
] | // String returns the string representation of an AuthType. | [
"String",
"returns",
"the",
"string",
"representation",
"of",
"an",
"AuthType",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/ipc/ipc.go#L48-L53 | train |
google/seesaw | common/ipc/ipc.go | NewContext | func NewContext(component seesaw.Component) *Context {
return &Context{
AuthType: ATNone,
Peer: Peer{
Component: component,
Identity: fmt.Sprintf("%s [pid %d]", component, os.Getpid()),
},
}
} | go | func NewContext(component seesaw.Component) *Context {
return &Context{
AuthType: ATNone,
Peer: Peer{
Component: component,
Identity: fmt.Sprintf("%s [pid %d]", component, os.Getpid()),
},
}
} | [
"func",
"NewContext",
"(",
"component",
"seesaw",
".",
"Component",
")",
"*",
"Context",
"{",
"return",
"&",
"Context",
"{",
"AuthType",
":",
"ATNone",
",",
"Peer",
":",
"Peer",
"{",
"Component",
":",
"component",
",",
"Identity",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"component",
",",
"os",
".",
"Getpid",
"(",
")",
")",
",",
"}",
",",
"}",
"\n",
"}"
] | // NewContext returns a new context for the given component. | [
"NewContext",
"returns",
"a",
"new",
"context",
"for",
"the",
"given",
"component",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/ipc/ipc.go#L72-L80 | train |
google/seesaw | common/ipc/ipc.go | NewAuthContext | func NewAuthContext(component seesaw.Component, token string) *Context {
ctx := NewContext(component)
ctx.AuthToken = token
ctx.AuthType = ATUntrusted
return ctx
} | go | func NewAuthContext(component seesaw.Component, token string) *Context {
ctx := NewContext(component)
ctx.AuthToken = token
ctx.AuthType = ATUntrusted
return ctx
} | [
"func",
"NewAuthContext",
"(",
"component",
"seesaw",
".",
"Component",
",",
"token",
"string",
")",
"*",
"Context",
"{",
"ctx",
":=",
"NewContext",
"(",
"component",
")",
"\n",
"ctx",
".",
"AuthToken",
"=",
"token",
"\n",
"ctx",
".",
"AuthType",
"=",
"ATUntrusted",
"\n",
"return",
"ctx",
"\n",
"}"
] | // NewAuthContext returns a new authenticated context for the given component. | [
"NewAuthContext",
"returns",
"a",
"new",
"authenticated",
"context",
"for",
"the",
"given",
"component",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/ipc/ipc.go#L83-L88 | train |
google/seesaw | common/ipc/ipc.go | NewTrustedContext | func NewTrustedContext(component seesaw.Component) *Context {
ctx := NewContext(component)
ctx.AuthType = ATTrusted
if u, err := user.Current(); err == nil {
ctx.User = fmt.Sprintf("%s [uid %s]", u.Username, u.Uid)
} else {
ctx.User = fmt.Sprintf("(unknown) [uid %d]", os.Getuid())
}
return ctx
} | go | func NewTrustedContext(component seesaw.Component) *Context {
ctx := NewContext(component)
ctx.AuthType = ATTrusted
if u, err := user.Current(); err == nil {
ctx.User = fmt.Sprintf("%s [uid %s]", u.Username, u.Uid)
} else {
ctx.User = fmt.Sprintf("(unknown) [uid %d]", os.Getuid())
}
return ctx
} | [
"func",
"NewTrustedContext",
"(",
"component",
"seesaw",
".",
"Component",
")",
"*",
"Context",
"{",
"ctx",
":=",
"NewContext",
"(",
"component",
")",
"\n",
"ctx",
".",
"AuthType",
"=",
"ATTrusted",
"\n",
"if",
"u",
",",
"err",
":=",
"user",
".",
"Current",
"(",
")",
";",
"err",
"==",
"nil",
"{",
"ctx",
".",
"User",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"u",
".",
"Username",
",",
"u",
".",
"Uid",
")",
"\n",
"}",
"else",
"{",
"ctx",
".",
"User",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"os",
".",
"Getuid",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"ctx",
"\n",
"}"
] | // NewTrustedContext returns a new trusted context for the given component. | [
"NewTrustedContext",
"returns",
"a",
"new",
"trusted",
"context",
"for",
"the",
"given",
"component",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/ipc/ipc.go#L91-L100 | train |
google/seesaw | common/ipc/ipc.go | String | func (ctx *Context) String() string {
if ctx == nil {
return "(nil context)"
}
var s []string
if ctx.Peer.Component != seesaw.SCNone {
s = append(s, fmt.Sprintf("peer %s", ctx.Peer.Identity))
}
if ctx.Proxy.Component != seesaw.SCNone {
s = append(s, fmt.Sprintf("via %s", ctx.Proxy.Identity))
}
s = append(s, fmt.Sprintf("as %s (%v auth)", ctx.User, ctx.AuthType))
return strings.Join(s, " ")
} | go | func (ctx *Context) String() string {
if ctx == nil {
return "(nil context)"
}
var s []string
if ctx.Peer.Component != seesaw.SCNone {
s = append(s, fmt.Sprintf("peer %s", ctx.Peer.Identity))
}
if ctx.Proxy.Component != seesaw.SCNone {
s = append(s, fmt.Sprintf("via %s", ctx.Proxy.Identity))
}
s = append(s, fmt.Sprintf("as %s (%v auth)", ctx.User, ctx.AuthType))
return strings.Join(s, " ")
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"String",
"(",
")",
"string",
"{",
"if",
"ctx",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"var",
"s",
"[",
"]",
"string",
"\n",
"if",
"ctx",
".",
"Peer",
".",
"Component",
"!=",
"seesaw",
".",
"SCNone",
"{",
"s",
"=",
"append",
"(",
"s",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ctx",
".",
"Peer",
".",
"Identity",
")",
")",
"\n",
"}",
"\n",
"if",
"ctx",
".",
"Proxy",
".",
"Component",
"!=",
"seesaw",
".",
"SCNone",
"{",
"s",
"=",
"append",
"(",
"s",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ctx",
".",
"Proxy",
".",
"Identity",
")",
")",
"\n",
"}",
"\n",
"s",
"=",
"append",
"(",
"s",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ctx",
".",
"User",
",",
"ctx",
".",
"AuthType",
")",
")",
"\n",
"return",
"strings",
".",
"Join",
"(",
"s",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // String returns the string representation of a context. | [
"String",
"returns",
"the",
"string",
"representation",
"of",
"a",
"context",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/ipc/ipc.go#L103-L117 | train |
google/seesaw | ecu/core.go | NewECU | func NewECU(cfg *ECUConfig) *ECU {
if cfg == nil {
defaultCfg := DefaultECUConfig()
cfg = &defaultCfg
}
return &ECU{
cfg: cfg,
shutdown: make(chan bool),
shutdownControl: make(chan bool),
shutdownMonitor: make(chan bool),
}
} | go | func NewECU(cfg *ECUConfig) *ECU {
if cfg == nil {
defaultCfg := DefaultECUConfig()
cfg = &defaultCfg
}
return &ECU{
cfg: cfg,
shutdown: make(chan bool),
shutdownControl: make(chan bool),
shutdownMonitor: make(chan bool),
}
} | [
"func",
"NewECU",
"(",
"cfg",
"*",
"ECUConfig",
")",
"*",
"ECU",
"{",
"if",
"cfg",
"==",
"nil",
"{",
"defaultCfg",
":=",
"DefaultECUConfig",
"(",
")",
"\n",
"cfg",
"=",
"&",
"defaultCfg",
"\n",
"}",
"\n",
"return",
"&",
"ECU",
"{",
"cfg",
":",
"cfg",
",",
"shutdown",
":",
"make",
"(",
"chan",
"bool",
")",
",",
"shutdownControl",
":",
"make",
"(",
"chan",
"bool",
")",
",",
"shutdownMonitor",
":",
"make",
"(",
"chan",
"bool",
")",
",",
"}",
"\n",
"}"
] | // NewECU returns an initialised ECU struct. | [
"NewECU",
"returns",
"an",
"initialised",
"ECU",
"struct",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ecu/core.go#L77-L88 | train |
google/seesaw | ecu/core.go | Run | func (e *ECU) Run() {
if err := e.authInit(); err != nil {
log.Warningf("Failed to initialise authentication, remote control will likely fail: %v", err)
}
stats := newECUStats(e)
go stats.run()
go e.control()
go e.monitoring()
<-e.shutdown
e.shutdownControl <- true
e.shutdownMonitor <- true
<-e.shutdownControl
<-e.shutdownMonitor
} | go | func (e *ECU) Run() {
if err := e.authInit(); err != nil {
log.Warningf("Failed to initialise authentication, remote control will likely fail: %v", err)
}
stats := newECUStats(e)
go stats.run()
go e.control()
go e.monitoring()
<-e.shutdown
e.shutdownControl <- true
e.shutdownMonitor <- true
<-e.shutdownControl
<-e.shutdownMonitor
} | [
"func",
"(",
"e",
"*",
"ECU",
")",
"Run",
"(",
")",
"{",
"if",
"err",
":=",
"e",
".",
"authInit",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"stats",
":=",
"newECUStats",
"(",
"e",
")",
"\n",
"go",
"stats",
".",
"run",
"(",
")",
"\n\n",
"go",
"e",
".",
"control",
"(",
")",
"\n",
"go",
"e",
".",
"monitoring",
"(",
")",
"\n\n",
"<-",
"e",
".",
"shutdown",
"\n",
"e",
".",
"shutdownControl",
"<-",
"true",
"\n",
"e",
".",
"shutdownMonitor",
"<-",
"true",
"\n",
"<-",
"e",
".",
"shutdownControl",
"\n",
"<-",
"e",
".",
"shutdownMonitor",
"\n",
"}"
] | // Run starts the ECU. | [
"Run",
"starts",
"the",
"ECU",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ecu/core.go#L91-L107 | train |
google/seesaw | ecu/core.go | monitoring | func (e *ECU) monitoring() {
ln, err := net.Listen("tcp", e.cfg.MonitorAddress)
if err != nil {
log.Fatal("listen error:", err)
}
monitorHTTP := &http.Server{
ReadTimeout: 30 * time.Second,
WriteTimeout: 30 * time.Second,
MaxHeaderBytes: 1 << 20,
}
go monitorHTTP.Serve(ln)
<-e.shutdownMonitor
ln.Close()
e.shutdownMonitor <- true
} | go | func (e *ECU) monitoring() {
ln, err := net.Listen("tcp", e.cfg.MonitorAddress)
if err != nil {
log.Fatal("listen error:", err)
}
monitorHTTP := &http.Server{
ReadTimeout: 30 * time.Second,
WriteTimeout: 30 * time.Second,
MaxHeaderBytes: 1 << 20,
}
go monitorHTTP.Serve(ln)
<-e.shutdownMonitor
ln.Close()
e.shutdownMonitor <- true
} | [
"func",
"(",
"e",
"*",
"ECU",
")",
"monitoring",
"(",
")",
"{",
"ln",
",",
"err",
":=",
"net",
".",
"Listen",
"(",
"\"",
"\"",
",",
"e",
".",
"cfg",
".",
"MonitorAddress",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatal",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"monitorHTTP",
":=",
"&",
"http",
".",
"Server",
"{",
"ReadTimeout",
":",
"30",
"*",
"time",
".",
"Second",
",",
"WriteTimeout",
":",
"30",
"*",
"time",
".",
"Second",
",",
"MaxHeaderBytes",
":",
"1",
"<<",
"20",
",",
"}",
"\n",
"go",
"monitorHTTP",
".",
"Serve",
"(",
"ln",
")",
"\n\n",
"<-",
"e",
".",
"shutdownMonitor",
"\n",
"ln",
".",
"Close",
"(",
")",
"\n",
"e",
".",
"shutdownMonitor",
"<-",
"true",
"\n",
"}"
] | // monitoring starts an HTTP server for monitoring purposes. | [
"monitoring",
"starts",
"an",
"HTTP",
"server",
"for",
"monitoring",
"purposes",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ecu/core.go#L115-L131 | train |
google/seesaw | ecu/core.go | controlTLSConfig | func (e *ECU) controlTLSConfig() (*tls.Config, error) {
rootCACerts := x509.NewCertPool()
data, err := ioutil.ReadFile(e.cfg.CACertsFile)
if err != nil {
return nil, fmt.Errorf("failed to read CA cert file: %v", err)
}
if ok := rootCACerts.AppendCertsFromPEM(data); !ok {
return nil, errors.New("failed to load CA certificates")
}
certs, err := tls.LoadX509KeyPair(e.cfg.ECUCertFile, e.cfg.ECUKeyFile)
if err != nil {
return nil, fmt.Errorf("failed to load X.509 key pair: %v", err)
}
// TODO(jsing): Make the server name configurable.
tlsConfig := &tls.Config{
Certificates: []tls.Certificate{certs},
RootCAs: rootCACerts,
ServerName: "seesaw.example.com",
}
return tlsConfig, nil
} | go | func (e *ECU) controlTLSConfig() (*tls.Config, error) {
rootCACerts := x509.NewCertPool()
data, err := ioutil.ReadFile(e.cfg.CACertsFile)
if err != nil {
return nil, fmt.Errorf("failed to read CA cert file: %v", err)
}
if ok := rootCACerts.AppendCertsFromPEM(data); !ok {
return nil, errors.New("failed to load CA certificates")
}
certs, err := tls.LoadX509KeyPair(e.cfg.ECUCertFile, e.cfg.ECUKeyFile)
if err != nil {
return nil, fmt.Errorf("failed to load X.509 key pair: %v", err)
}
// TODO(jsing): Make the server name configurable.
tlsConfig := &tls.Config{
Certificates: []tls.Certificate{certs},
RootCAs: rootCACerts,
ServerName: "seesaw.example.com",
}
return tlsConfig, nil
} | [
"func",
"(",
"e",
"*",
"ECU",
")",
"controlTLSConfig",
"(",
")",
"(",
"*",
"tls",
".",
"Config",
",",
"error",
")",
"{",
"rootCACerts",
":=",
"x509",
".",
"NewCertPool",
"(",
")",
"\n",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"e",
".",
"cfg",
".",
"CACertsFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"ok",
":=",
"rootCACerts",
".",
"AppendCertsFromPEM",
"(",
"data",
")",
";",
"!",
"ok",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"certs",
",",
"err",
":=",
"tls",
".",
"LoadX509KeyPair",
"(",
"e",
".",
"cfg",
".",
"ECUCertFile",
",",
"e",
".",
"cfg",
".",
"ECUKeyFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"// TODO(jsing): Make the server name configurable.",
"tlsConfig",
":=",
"&",
"tls",
".",
"Config",
"{",
"Certificates",
":",
"[",
"]",
"tls",
".",
"Certificate",
"{",
"certs",
"}",
",",
"RootCAs",
":",
"rootCACerts",
",",
"ServerName",
":",
"\"",
"\"",
",",
"}",
"\n",
"return",
"tlsConfig",
",",
"nil",
"\n",
"}"
] | // controlTLSConfig returns a TLS configuration for use by the control server. | [
"controlTLSConfig",
"returns",
"a",
"TLS",
"configuration",
"for",
"use",
"by",
"the",
"control",
"server",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ecu/core.go#L134-L154 | train |
google/seesaw | ecu/core.go | control | func (e *ECU) control() {
tlsConfig, err := e.controlTLSConfig()
if err != nil {
log.Errorf("Disabling ECU control server: %v", err)
<-e.shutdownControl
e.shutdownControl <- true
return
}
ln, err := net.Listen("tcp", e.cfg.ControlAddress)
if err != nil {
log.Fatal("listen error:", err)
}
seesawRPC := rpc.NewServer()
seesawRPC.Register(&SeesawECU{e})
tlsListener := tls.NewListener(ln, tlsConfig)
go server.RPCAccept(tlsListener, seesawRPC)
<-e.shutdownControl
ln.Close()
e.shutdownControl <- true
} | go | func (e *ECU) control() {
tlsConfig, err := e.controlTLSConfig()
if err != nil {
log.Errorf("Disabling ECU control server: %v", err)
<-e.shutdownControl
e.shutdownControl <- true
return
}
ln, err := net.Listen("tcp", e.cfg.ControlAddress)
if err != nil {
log.Fatal("listen error:", err)
}
seesawRPC := rpc.NewServer()
seesawRPC.Register(&SeesawECU{e})
tlsListener := tls.NewListener(ln, tlsConfig)
go server.RPCAccept(tlsListener, seesawRPC)
<-e.shutdownControl
ln.Close()
e.shutdownControl <- true
} | [
"func",
"(",
"e",
"*",
"ECU",
")",
"control",
"(",
")",
"{",
"tlsConfig",
",",
"err",
":=",
"e",
".",
"controlTLSConfig",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"<-",
"e",
".",
"shutdownControl",
"\n",
"e",
".",
"shutdownControl",
"<-",
"true",
"\n",
"return",
"\n",
"}",
"\n\n",
"ln",
",",
"err",
":=",
"net",
".",
"Listen",
"(",
"\"",
"\"",
",",
"e",
".",
"cfg",
".",
"ControlAddress",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatal",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"seesawRPC",
":=",
"rpc",
".",
"NewServer",
"(",
")",
"\n",
"seesawRPC",
".",
"Register",
"(",
"&",
"SeesawECU",
"{",
"e",
"}",
")",
"\n",
"tlsListener",
":=",
"tls",
".",
"NewListener",
"(",
"ln",
",",
"tlsConfig",
")",
"\n",
"go",
"server",
".",
"RPCAccept",
"(",
"tlsListener",
",",
"seesawRPC",
")",
"\n\n",
"<-",
"e",
".",
"shutdownControl",
"\n",
"ln",
".",
"Close",
"(",
")",
"\n",
"e",
".",
"shutdownControl",
"<-",
"true",
"\n",
"}"
] | // control starts an HTTP server to handle control RPC via a TCP socket. This
// interface is used to control the Seesaw Node via the CLI or web console. | [
"control",
"starts",
"an",
"HTTP",
"server",
"to",
"handle",
"control",
"RPC",
"via",
"a",
"TCP",
"socket",
".",
"This",
"interface",
"is",
"used",
"to",
"control",
"the",
"Seesaw",
"Node",
"via",
"the",
"CLI",
"or",
"web",
"console",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ecu/core.go#L158-L180 | train |
google/seesaw | ncc/sysctl.go | sysctlInitLB | func sysctlInitLB(nodeIface, lbIface *net.Interface) error {
// System level sysctls.
for _, ctl := range seesawSysctls {
if _, err := sysctl(ctl.name, ctl.value); err != nil {
return err
}
}
// Interface level sysctls.
ifaces := []string{"all", "default", nodeIface.Name, lbIface.Name}
for _, iface := range ifaces {
if err := sysctlInitIface(iface); err != nil {
return err
}
}
return nil
} | go | func sysctlInitLB(nodeIface, lbIface *net.Interface) error {
// System level sysctls.
for _, ctl := range seesawSysctls {
if _, err := sysctl(ctl.name, ctl.value); err != nil {
return err
}
}
// Interface level sysctls.
ifaces := []string{"all", "default", nodeIface.Name, lbIface.Name}
for _, iface := range ifaces {
if err := sysctlInitIface(iface); err != nil {
return err
}
}
return nil
} | [
"func",
"sysctlInitLB",
"(",
"nodeIface",
",",
"lbIface",
"*",
"net",
".",
"Interface",
")",
"error",
"{",
"// System level sysctls.",
"for",
"_",
",",
"ctl",
":=",
"range",
"seesawSysctls",
"{",
"if",
"_",
",",
"err",
":=",
"sysctl",
"(",
"ctl",
".",
"name",
",",
"ctl",
".",
"value",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Interface level sysctls.",
"ifaces",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nodeIface",
".",
"Name",
",",
"lbIface",
".",
"Name",
"}",
"\n",
"for",
"_",
",",
"iface",
":=",
"range",
"ifaces",
"{",
"if",
"err",
":=",
"sysctlInitIface",
"(",
"iface",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // sysctlInitLB initialises sysctls required for load balancing. | [
"sysctlInitLB",
"initialises",
"sysctls",
"required",
"for",
"load",
"balancing",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/sysctl.go#L91-L108 | train |
google/seesaw | ncc/sysctl.go | sysctlInitIface | func sysctlInitIface(iface string) error {
for _, ctl := range seesawIfaceSysctls {
if err := sysctlIface(iface, ctl.af, ctl.name, ctl.value); err != nil {
return err
}
}
return nil
} | go | func sysctlInitIface(iface string) error {
for _, ctl := range seesawIfaceSysctls {
if err := sysctlIface(iface, ctl.af, ctl.name, ctl.value); err != nil {
return err
}
}
return nil
} | [
"func",
"sysctlInitIface",
"(",
"iface",
"string",
")",
"error",
"{",
"for",
"_",
",",
"ctl",
":=",
"range",
"seesawIfaceSysctls",
"{",
"if",
"err",
":=",
"sysctlIface",
"(",
"iface",
",",
"ctl",
".",
"af",
",",
"ctl",
".",
"name",
",",
"ctl",
".",
"value",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // sysctlInitIface initialises sysctls required for a load balancing interface. | [
"sysctlInitIface",
"initialises",
"sysctls",
"required",
"for",
"a",
"load",
"balancing",
"interface",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/sysctl.go#L111-L118 | train |
google/seesaw | ncc/sysctl.go | sysctlIface | func sysctlIface(iface string, af seesaw.AF, name, value string) error {
components := []string{
"net", strings.ToLower(af.String()), "conf", iface, name,
}
_, err := sysctlByComponents(components, value)
return err
} | go | func sysctlIface(iface string, af seesaw.AF, name, value string) error {
components := []string{
"net", strings.ToLower(af.String()), "conf", iface, name,
}
_, err := sysctlByComponents(components, value)
return err
} | [
"func",
"sysctlIface",
"(",
"iface",
"string",
",",
"af",
"seesaw",
".",
"AF",
",",
"name",
",",
"value",
"string",
")",
"error",
"{",
"components",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"strings",
".",
"ToLower",
"(",
"af",
".",
"String",
"(",
")",
")",
",",
"\"",
"\"",
",",
"iface",
",",
"name",
",",
"}",
"\n",
"_",
",",
"err",
":=",
"sysctlByComponents",
"(",
"components",
",",
"value",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // sysctlIface sets a sysctl for a given address family and network interface. | [
"sysctlIface",
"sets",
"a",
"sysctl",
"for",
"a",
"given",
"address",
"family",
"and",
"network",
"interface",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/sysctl.go#L121-L127 | train |
google/seesaw | ncc/sysctl.go | sysctl | func sysctl(name, value string) (string, error) {
return sysctlByComponents(strings.Split(name, "."), value)
} | go | func sysctl(name, value string) (string, error) {
return sysctlByComponents(strings.Split(name, "."), value)
} | [
"func",
"sysctl",
"(",
"name",
",",
"value",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"return",
"sysctlByComponents",
"(",
"strings",
".",
"Split",
"(",
"name",
",",
"\"",
"\"",
")",
",",
"value",
")",
"\n",
"}"
] | // sysctl sets the named sysctl to the value specified and returns its
// original value as a string. Note that this cannot be used if a sysctl
// component includes a period it its name - in that case use
// sysctlByComponents instead. | [
"sysctl",
"sets",
"the",
"named",
"sysctl",
"to",
"the",
"value",
"specified",
"and",
"returns",
"its",
"original",
"value",
"as",
"a",
"string",
".",
"Note",
"that",
"this",
"cannot",
"be",
"used",
"if",
"a",
"sysctl",
"component",
"includes",
"a",
"period",
"it",
"its",
"name",
"-",
"in",
"that",
"case",
"use",
"sysctlByComponents",
"instead",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/sysctl.go#L133-L135 | train |
google/seesaw | ncc/sysctl.go | sysctlByComponents | func sysctlByComponents(components []string, value string) (string, error) {
components = append([]string{sysctlPath}, components...)
f, err := os.OpenFile(path.Join(components...), os.O_RDWR, 0)
if err != nil {
return "", err
}
defer f.Close()
b, err := ioutil.ReadAll(f)
if err != nil {
return "", err
}
if _, err := f.Seek(0, 0); err != nil {
return "", err
}
if _, err := fmt.Fprintf(f, "%s\n", value); err != nil {
return "", err
}
return strings.TrimRight(string(b), "\n"), nil
} | go | func sysctlByComponents(components []string, value string) (string, error) {
components = append([]string{sysctlPath}, components...)
f, err := os.OpenFile(path.Join(components...), os.O_RDWR, 0)
if err != nil {
return "", err
}
defer f.Close()
b, err := ioutil.ReadAll(f)
if err != nil {
return "", err
}
if _, err := f.Seek(0, 0); err != nil {
return "", err
}
if _, err := fmt.Fprintf(f, "%s\n", value); err != nil {
return "", err
}
return strings.TrimRight(string(b), "\n"), nil
} | [
"func",
"sysctlByComponents",
"(",
"components",
"[",
"]",
"string",
",",
"value",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"components",
"=",
"append",
"(",
"[",
"]",
"string",
"{",
"sysctlPath",
"}",
",",
"components",
"...",
")",
"\n",
"f",
",",
"err",
":=",
"os",
".",
"OpenFile",
"(",
"path",
".",
"Join",
"(",
"components",
"...",
")",
",",
"os",
".",
"O_RDWR",
",",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n",
"b",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"f",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"_",
",",
"err",
":=",
"f",
".",
"Seek",
"(",
"0",
",",
"0",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"_",
",",
"err",
":=",
"fmt",
".",
"Fprintf",
"(",
"f",
",",
"\"",
"\\n",
"\"",
",",
"value",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"strings",
".",
"TrimRight",
"(",
"string",
"(",
"b",
")",
",",
"\"",
"\\n",
"\"",
")",
",",
"nil",
"\n",
"}"
] | // sysctlByComponents sets the sysctl specified by the individual components
// to the value specified and returns its original value as a string. | [
"sysctlByComponents",
"sets",
"the",
"sysctl",
"specified",
"by",
"the",
"individual",
"components",
"to",
"the",
"value",
"specified",
"and",
"returns",
"its",
"original",
"value",
"as",
"a",
"string",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/sysctl.go#L139-L157 | train |
google/seesaw | ncc/iptables.go | newIPTRuleTemplate | func newIPTRuleTemplate(action iptAction, tmpl string) *iptRuleTemplate {
t, err := template.New("").Parse(tmpl)
if err != nil {
panic(fmt.Sprintf("Failed to parse iptables template: %q: %v", tmpl, err))
}
return &iptRuleTemplate{action, t}
} | go | func newIPTRuleTemplate(action iptAction, tmpl string) *iptRuleTemplate {
t, err := template.New("").Parse(tmpl)
if err != nil {
panic(fmt.Sprintf("Failed to parse iptables template: %q: %v", tmpl, err))
}
return &iptRuleTemplate{action, t}
} | [
"func",
"newIPTRuleTemplate",
"(",
"action",
"iptAction",
",",
"tmpl",
"string",
")",
"*",
"iptRuleTemplate",
"{",
"t",
",",
"err",
":=",
"template",
".",
"New",
"(",
"\"",
"\"",
")",
".",
"Parse",
"(",
"tmpl",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"tmpl",
",",
"err",
")",
")",
"\n",
"}",
"\n",
"return",
"&",
"iptRuleTemplate",
"{",
"action",
",",
"t",
"}",
"\n",
"}"
] | // newIPTRuleTemplate creates a new iptRuleTemplate. | [
"newIPTRuleTemplate",
"creates",
"a",
"new",
"iptRuleTemplate",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/iptables.go#L77-L83 | train |
google/seesaw | ncc/iptables.go | execute | func (te *iptTemplateExecuter) execute() ([]*iptRule, error) {
rules := make([]*iptRule, 0, len(te.templates))
for _, t := range te.templates {
w := new(bytes.Buffer)
if err := t.Template.Execute(w, te.data); err != nil {
return nil, err
}
af := seesaw.IPv6
if te.data.ServiceVIP.To4() != nil {
af = seesaw.IPv4
}
rule := &iptRule{
af,
t.action,
w.String(),
}
rules = append(rules, rule)
}
return rules, nil
} | go | func (te *iptTemplateExecuter) execute() ([]*iptRule, error) {
rules := make([]*iptRule, 0, len(te.templates))
for _, t := range te.templates {
w := new(bytes.Buffer)
if err := t.Template.Execute(w, te.data); err != nil {
return nil, err
}
af := seesaw.IPv6
if te.data.ServiceVIP.To4() != nil {
af = seesaw.IPv4
}
rule := &iptRule{
af,
t.action,
w.String(),
}
rules = append(rules, rule)
}
return rules, nil
} | [
"func",
"(",
"te",
"*",
"iptTemplateExecuter",
")",
"execute",
"(",
")",
"(",
"[",
"]",
"*",
"iptRule",
",",
"error",
")",
"{",
"rules",
":=",
"make",
"(",
"[",
"]",
"*",
"iptRule",
",",
"0",
",",
"len",
"(",
"te",
".",
"templates",
")",
")",
"\n",
"for",
"_",
",",
"t",
":=",
"range",
"te",
".",
"templates",
"{",
"w",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"if",
"err",
":=",
"t",
".",
"Template",
".",
"Execute",
"(",
"w",
",",
"te",
".",
"data",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"af",
":=",
"seesaw",
".",
"IPv6",
"\n",
"if",
"te",
".",
"data",
".",
"ServiceVIP",
".",
"To4",
"(",
")",
"!=",
"nil",
"{",
"af",
"=",
"seesaw",
".",
"IPv4",
"\n",
"}",
"\n",
"rule",
":=",
"&",
"iptRule",
"{",
"af",
",",
"t",
".",
"action",
",",
"w",
".",
"String",
"(",
")",
",",
"}",
"\n",
"rules",
"=",
"append",
"(",
"rules",
",",
"rule",
")",
"\n",
"}",
"\n",
"return",
"rules",
",",
"nil",
"\n",
"}"
] | // execute generates the list of iptRules for this iptTemplateExecuter. | [
"execute",
"generates",
"the",
"list",
"of",
"iptRules",
"for",
"this",
"iptTemplateExecuter",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/iptables.go#L103-L122 | train |
google/seesaw | ncc/iptables.go | initIPTRuleTemplates | func initIPTRuleTemplates() {
// Allow traffic for VIP services.
svcRules = append(svcRules, newIPTRuleTemplate(iptAppend,
"INPUT -p {{.Proto}} -d {{.ServiceVIP}}{{with .Port}} --dport {{.}}{{end}} -j ACCEPT"))
// Mark packets for firemark based VIPs.
fwmRule := "PREROUTING -t mangle -p {{.Proto}} -d {{.ServiceVIP}}" +
"{{with .Port}} --dport {{.}}{{end}} -j MARK --set-mark {{.FWM}}"
fwmRules = append(fwmRules, newIPTRuleTemplate(iptAppend, fwmRule))
// Enable conntrack for NAT connections.
natConntrack := "PREROUTING -t raw -p {{.Proto}} -d {{.ServiceVIP}}" +
"{{with .Port}} --dport {{.}}{{end}} -j ACCEPT"
natRules = append(natRules, newIPTRuleTemplate(iptInsert, natConntrack))
// Rewrite source address for NAT'd packets so backend reply traffic comes
// back to the load balancer.
natPostrouting := "POSTROUTING -t nat -m ipvs -p {{.Proto}}{{with .Port}} --vport {{.}}{{end}} " +
"--vaddr {{.ServiceVIP}} -j SNAT --to-source {{.ClusterVIP}} --random"
natRules = append(natRules, newIPTRuleTemplate(iptAppend, natPostrouting))
// Allow ICMP traffic to this VIP.
vipRulesEnd = append(vipRulesEnd, newIPTRuleTemplate(iptAppend,
"INPUT -p icmp -d {{.ServiceVIP}} -j ACCEPT"))
vipRulesEnd = append(vipRulesEnd, newIPTRuleTemplate(iptAppend,
"INPUT -p ipv6-icmp -d {{.ServiceVIP}} -j ACCEPT"))
// Block all other traffic to this VIP.
vipRulesEnd = append(vipRulesEnd, newIPTRuleTemplate(iptAppend,
"INPUT -d {{.ServiceVIP}} -j REJECT"))
} | go | func initIPTRuleTemplates() {
// Allow traffic for VIP services.
svcRules = append(svcRules, newIPTRuleTemplate(iptAppend,
"INPUT -p {{.Proto}} -d {{.ServiceVIP}}{{with .Port}} --dport {{.}}{{end}} -j ACCEPT"))
// Mark packets for firemark based VIPs.
fwmRule := "PREROUTING -t mangle -p {{.Proto}} -d {{.ServiceVIP}}" +
"{{with .Port}} --dport {{.}}{{end}} -j MARK --set-mark {{.FWM}}"
fwmRules = append(fwmRules, newIPTRuleTemplate(iptAppend, fwmRule))
// Enable conntrack for NAT connections.
natConntrack := "PREROUTING -t raw -p {{.Proto}} -d {{.ServiceVIP}}" +
"{{with .Port}} --dport {{.}}{{end}} -j ACCEPT"
natRules = append(natRules, newIPTRuleTemplate(iptInsert, natConntrack))
// Rewrite source address for NAT'd packets so backend reply traffic comes
// back to the load balancer.
natPostrouting := "POSTROUTING -t nat -m ipvs -p {{.Proto}}{{with .Port}} --vport {{.}}{{end}} " +
"--vaddr {{.ServiceVIP}} -j SNAT --to-source {{.ClusterVIP}} --random"
natRules = append(natRules, newIPTRuleTemplate(iptAppend, natPostrouting))
// Allow ICMP traffic to this VIP.
vipRulesEnd = append(vipRulesEnd, newIPTRuleTemplate(iptAppend,
"INPUT -p icmp -d {{.ServiceVIP}} -j ACCEPT"))
vipRulesEnd = append(vipRulesEnd, newIPTRuleTemplate(iptAppend,
"INPUT -p ipv6-icmp -d {{.ServiceVIP}} -j ACCEPT"))
// Block all other traffic to this VIP.
vipRulesEnd = append(vipRulesEnd, newIPTRuleTemplate(iptAppend,
"INPUT -d {{.ServiceVIP}} -j REJECT"))
} | [
"func",
"initIPTRuleTemplates",
"(",
")",
"{",
"// Allow traffic for VIP services.",
"svcRules",
"=",
"append",
"(",
"svcRules",
",",
"newIPTRuleTemplate",
"(",
"iptAppend",
",",
"\"",
"\"",
")",
")",
"\n\n",
"// Mark packets for firemark based VIPs.",
"fwmRule",
":=",
"\"",
"\"",
"+",
"\"",
"\"",
"\n",
"fwmRules",
"=",
"append",
"(",
"fwmRules",
",",
"newIPTRuleTemplate",
"(",
"iptAppend",
",",
"fwmRule",
")",
")",
"\n\n",
"// Enable conntrack for NAT connections.",
"natConntrack",
":=",
"\"",
"\"",
"+",
"\"",
"\"",
"\n",
"natRules",
"=",
"append",
"(",
"natRules",
",",
"newIPTRuleTemplate",
"(",
"iptInsert",
",",
"natConntrack",
")",
")",
"\n\n",
"// Rewrite source address for NAT'd packets so backend reply traffic comes",
"// back to the load balancer.",
"natPostrouting",
":=",
"\"",
"\"",
"+",
"\"",
"\"",
"\n",
"natRules",
"=",
"append",
"(",
"natRules",
",",
"newIPTRuleTemplate",
"(",
"iptAppend",
",",
"natPostrouting",
")",
")",
"\n\n",
"// Allow ICMP traffic to this VIP.",
"vipRulesEnd",
"=",
"append",
"(",
"vipRulesEnd",
",",
"newIPTRuleTemplate",
"(",
"iptAppend",
",",
"\"",
"\"",
")",
")",
"\n",
"vipRulesEnd",
"=",
"append",
"(",
"vipRulesEnd",
",",
"newIPTRuleTemplate",
"(",
"iptAppend",
",",
"\"",
"\"",
")",
")",
"\n\n",
"// Block all other traffic to this VIP.",
"vipRulesEnd",
"=",
"append",
"(",
"vipRulesEnd",
",",
"newIPTRuleTemplate",
"(",
"iptAppend",
",",
"\"",
"\"",
")",
")",
"\n",
"}"
] | // initIPTRuleTemplates initialises the iptRuleTemplates. | [
"initIPTRuleTemplates",
"initialises",
"the",
"iptRuleTemplates",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/iptables.go#L132-L162 | train |
google/seesaw | ncc/iptables.go | iptablesInit | func iptablesInit(clusterVIP seesaw.Host) error {
if err := iptablesFlush(); err != nil {
return err
}
for _, af := range seesaw.AFs() {
// Allow connections to port 10257 for all VIPs.
if err := iptablesRun(af, "-I INPUT -p tcp --dport 10257 -j ACCEPT"); err != nil {
return err
}
// conntrack is only required for NAT. Disable it for everything else.
if err := iptablesRun(af, "-t raw -A PREROUTING -j NOTRACK"); err != nil {
return err
}
if err := iptablesRun(af, "-t raw -A OUTPUT -j NOTRACK"); err != nil {
return err
}
}
// Enable conntrack for incoming traffic on the seesaw cluster IPv4 VIP. This
// is required for NAT return traffic.
return iptablesRun(seesaw.IPv4,
fmt.Sprintf("-t raw -I PREROUTING -d %v/32 -j ACCEPT", clusterVIP.IPv4Addr))
} | go | func iptablesInit(clusterVIP seesaw.Host) error {
if err := iptablesFlush(); err != nil {
return err
}
for _, af := range seesaw.AFs() {
// Allow connections to port 10257 for all VIPs.
if err := iptablesRun(af, "-I INPUT -p tcp --dport 10257 -j ACCEPT"); err != nil {
return err
}
// conntrack is only required for NAT. Disable it for everything else.
if err := iptablesRun(af, "-t raw -A PREROUTING -j NOTRACK"); err != nil {
return err
}
if err := iptablesRun(af, "-t raw -A OUTPUT -j NOTRACK"); err != nil {
return err
}
}
// Enable conntrack for incoming traffic on the seesaw cluster IPv4 VIP. This
// is required for NAT return traffic.
return iptablesRun(seesaw.IPv4,
fmt.Sprintf("-t raw -I PREROUTING -d %v/32 -j ACCEPT", clusterVIP.IPv4Addr))
} | [
"func",
"iptablesInit",
"(",
"clusterVIP",
"seesaw",
".",
"Host",
")",
"error",
"{",
"if",
"err",
":=",
"iptablesFlush",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"af",
":=",
"range",
"seesaw",
".",
"AFs",
"(",
")",
"{",
"// Allow connections to port 10257 for all VIPs.",
"if",
"err",
":=",
"iptablesRun",
"(",
"af",
",",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// conntrack is only required for NAT. Disable it for everything else.",
"if",
"err",
":=",
"iptablesRun",
"(",
"af",
",",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"iptablesRun",
"(",
"af",
",",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Enable conntrack for incoming traffic on the seesaw cluster IPv4 VIP. This",
"// is required for NAT return traffic.",
"return",
"iptablesRun",
"(",
"seesaw",
".",
"IPv4",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"clusterVIP",
".",
"IPv4Addr",
")",
")",
"\n",
"}"
] | // iptablesInit initialises the iptables rules for a Seesaw Node. | [
"iptablesInit",
"initialises",
"the",
"iptables",
"rules",
"for",
"a",
"Seesaw",
"Node",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/iptables.go#L216-L239 | train |
google/seesaw | ncc/iptables.go | iptablesFlush | func iptablesFlush() error {
for _, af := range seesaw.AFs() {
for _, table := range []string{"filter", "mangle", "raw"} {
if err := iptablesRun(af, fmt.Sprintf("--flush -t %v", table)); err != nil {
return err
}
}
}
// NAT is IPv4-only until linux kernel version 3.7.
// TODO(angusc): Support IPv6 NAT.
if err := iptablesRun(seesaw.IPv4, "--flush -t nat"); err != nil {
return err
}
return nil
} | go | func iptablesFlush() error {
for _, af := range seesaw.AFs() {
for _, table := range []string{"filter", "mangle", "raw"} {
if err := iptablesRun(af, fmt.Sprintf("--flush -t %v", table)); err != nil {
return err
}
}
}
// NAT is IPv4-only until linux kernel version 3.7.
// TODO(angusc): Support IPv6 NAT.
if err := iptablesRun(seesaw.IPv4, "--flush -t nat"); err != nil {
return err
}
return nil
} | [
"func",
"iptablesFlush",
"(",
")",
"error",
"{",
"for",
"_",
",",
"af",
":=",
"range",
"seesaw",
".",
"AFs",
"(",
")",
"{",
"for",
"_",
",",
"table",
":=",
"range",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
"{",
"if",
"err",
":=",
"iptablesRun",
"(",
"af",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"table",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"// NAT is IPv4-only until linux kernel version 3.7.",
"// TODO(angusc): Support IPv6 NAT.",
"if",
"err",
":=",
"iptablesRun",
"(",
"seesaw",
".",
"IPv4",
",",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // iptablesFlush removes all IPv4 and IPv6 iptables rules. | [
"iptablesFlush",
"removes",
"all",
"IPv4",
"and",
"IPv6",
"iptables",
"rules",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/iptables.go#L242-L256 | train |
google/seesaw | ncc/iptables.go | iptablesRules | func iptablesRules(v *seesaw.Vserver, clusterVIP seesaw.Host, af seesaw.AF) ([]*iptRule, error) {
var clusterIP, serviceIP net.IP
switch af {
case seesaw.IPv4:
clusterIP = clusterVIP.IPv4Addr
serviceIP = v.IPv4Addr
case seesaw.IPv6:
clusterIP = clusterVIP.IPv6Addr
serviceIP = v.IPv6Addr
}
if clusterIP == nil {
return nil, fmt.Errorf("Seesaw Cluster VIP does not have an %s address", af)
}
if serviceIP == nil {
return nil, fmt.Errorf("Service VIP does not have an %s address", af)
}
executers := make([]*iptTemplateExecuter, 0)
vipData := &iptTemplateData{
ClusterVIP: clusterIP,
ServiceVIP: serviceIP,
}
executers = append(executers, &iptTemplateExecuter{vipRulesBegin, vipData})
for _, ve := range v.Entries {
svcData := &iptTemplateData{
ClusterVIP: clusterIP,
ServiceVIP: serviceIP,
FWM: v.FWM[af],
Port: ve.Port,
Proto: ve.Proto,
}
executers = append(executers, newIPTTemplateExecuter(svcRules, svcData))
if v.FWM[af] > 0 {
executers = append(executers, newIPTTemplateExecuter(fwmRules, svcData))
}
if ve.Mode == seesaw.LBModeNAT {
executers = append(executers, newIPTTemplateExecuter(natRules, svcData))
}
}
executers = append(executers, &iptTemplateExecuter{vipRulesEnd, vipData})
allRules := make([]*iptRule, 0)
for _, ex := range executers {
rules, err := ex.execute()
if err != nil {
return nil, err
}
allRules = append(allRules, rules...)
}
return allRules, nil
} | go | func iptablesRules(v *seesaw.Vserver, clusterVIP seesaw.Host, af seesaw.AF) ([]*iptRule, error) {
var clusterIP, serviceIP net.IP
switch af {
case seesaw.IPv4:
clusterIP = clusterVIP.IPv4Addr
serviceIP = v.IPv4Addr
case seesaw.IPv6:
clusterIP = clusterVIP.IPv6Addr
serviceIP = v.IPv6Addr
}
if clusterIP == nil {
return nil, fmt.Errorf("Seesaw Cluster VIP does not have an %s address", af)
}
if serviceIP == nil {
return nil, fmt.Errorf("Service VIP does not have an %s address", af)
}
executers := make([]*iptTemplateExecuter, 0)
vipData := &iptTemplateData{
ClusterVIP: clusterIP,
ServiceVIP: serviceIP,
}
executers = append(executers, &iptTemplateExecuter{vipRulesBegin, vipData})
for _, ve := range v.Entries {
svcData := &iptTemplateData{
ClusterVIP: clusterIP,
ServiceVIP: serviceIP,
FWM: v.FWM[af],
Port: ve.Port,
Proto: ve.Proto,
}
executers = append(executers, newIPTTemplateExecuter(svcRules, svcData))
if v.FWM[af] > 0 {
executers = append(executers, newIPTTemplateExecuter(fwmRules, svcData))
}
if ve.Mode == seesaw.LBModeNAT {
executers = append(executers, newIPTTemplateExecuter(natRules, svcData))
}
}
executers = append(executers, &iptTemplateExecuter{vipRulesEnd, vipData})
allRules := make([]*iptRule, 0)
for _, ex := range executers {
rules, err := ex.execute()
if err != nil {
return nil, err
}
allRules = append(allRules, rules...)
}
return allRules, nil
} | [
"func",
"iptablesRules",
"(",
"v",
"*",
"seesaw",
".",
"Vserver",
",",
"clusterVIP",
"seesaw",
".",
"Host",
",",
"af",
"seesaw",
".",
"AF",
")",
"(",
"[",
"]",
"*",
"iptRule",
",",
"error",
")",
"{",
"var",
"clusterIP",
",",
"serviceIP",
"net",
".",
"IP",
"\n",
"switch",
"af",
"{",
"case",
"seesaw",
".",
"IPv4",
":",
"clusterIP",
"=",
"clusterVIP",
".",
"IPv4Addr",
"\n",
"serviceIP",
"=",
"v",
".",
"IPv4Addr",
"\n",
"case",
"seesaw",
".",
"IPv6",
":",
"clusterIP",
"=",
"clusterVIP",
".",
"IPv6Addr",
"\n",
"serviceIP",
"=",
"v",
".",
"IPv6Addr",
"\n",
"}",
"\n",
"if",
"clusterIP",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"af",
")",
"\n",
"}",
"\n",
"if",
"serviceIP",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"af",
")",
"\n",
"}",
"\n\n",
"executers",
":=",
"make",
"(",
"[",
"]",
"*",
"iptTemplateExecuter",
",",
"0",
")",
"\n",
"vipData",
":=",
"&",
"iptTemplateData",
"{",
"ClusterVIP",
":",
"clusterIP",
",",
"ServiceVIP",
":",
"serviceIP",
",",
"}",
"\n",
"executers",
"=",
"append",
"(",
"executers",
",",
"&",
"iptTemplateExecuter",
"{",
"vipRulesBegin",
",",
"vipData",
"}",
")",
"\n\n",
"for",
"_",
",",
"ve",
":=",
"range",
"v",
".",
"Entries",
"{",
"svcData",
":=",
"&",
"iptTemplateData",
"{",
"ClusterVIP",
":",
"clusterIP",
",",
"ServiceVIP",
":",
"serviceIP",
",",
"FWM",
":",
"v",
".",
"FWM",
"[",
"af",
"]",
",",
"Port",
":",
"ve",
".",
"Port",
",",
"Proto",
":",
"ve",
".",
"Proto",
",",
"}",
"\n",
"executers",
"=",
"append",
"(",
"executers",
",",
"newIPTTemplateExecuter",
"(",
"svcRules",
",",
"svcData",
")",
")",
"\n\n",
"if",
"v",
".",
"FWM",
"[",
"af",
"]",
">",
"0",
"{",
"executers",
"=",
"append",
"(",
"executers",
",",
"newIPTTemplateExecuter",
"(",
"fwmRules",
",",
"svcData",
")",
")",
"\n",
"}",
"\n\n",
"if",
"ve",
".",
"Mode",
"==",
"seesaw",
".",
"LBModeNAT",
"{",
"executers",
"=",
"append",
"(",
"executers",
",",
"newIPTTemplateExecuter",
"(",
"natRules",
",",
"svcData",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"executers",
"=",
"append",
"(",
"executers",
",",
"&",
"iptTemplateExecuter",
"{",
"vipRulesEnd",
",",
"vipData",
"}",
")",
"\n\n",
"allRules",
":=",
"make",
"(",
"[",
"]",
"*",
"iptRule",
",",
"0",
")",
"\n",
"for",
"_",
",",
"ex",
":=",
"range",
"executers",
"{",
"rules",
",",
"err",
":=",
"ex",
".",
"execute",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"allRules",
"=",
"append",
"(",
"allRules",
",",
"rules",
"...",
")",
"\n",
"}",
"\n",
"return",
"allRules",
",",
"nil",
"\n",
"}"
] | // iptablesRules returns the list of iptRules for a Vserver. | [
"iptablesRules",
"returns",
"the",
"list",
"of",
"iptRules",
"for",
"a",
"Vserver",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/iptables.go#L259-L313 | train |
google/seesaw | ncc/iptables.go | iptablesAddRules | func iptablesAddRules(v *seesaw.Vserver, clusterVIP seesaw.Host, af seesaw.AF) error {
rules, err := iptablesRules(v, clusterVIP, af)
if err != nil {
return err
}
for _, r := range rules {
if err := iptablesRun(r.AF, string(r.action)+" "+r.rule); err != nil {
return err
}
}
return nil
} | go | func iptablesAddRules(v *seesaw.Vserver, clusterVIP seesaw.Host, af seesaw.AF) error {
rules, err := iptablesRules(v, clusterVIP, af)
if err != nil {
return err
}
for _, r := range rules {
if err := iptablesRun(r.AF, string(r.action)+" "+r.rule); err != nil {
return err
}
}
return nil
} | [
"func",
"iptablesAddRules",
"(",
"v",
"*",
"seesaw",
".",
"Vserver",
",",
"clusterVIP",
"seesaw",
".",
"Host",
",",
"af",
"seesaw",
".",
"AF",
")",
"error",
"{",
"rules",
",",
"err",
":=",
"iptablesRules",
"(",
"v",
",",
"clusterVIP",
",",
"af",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"rules",
"{",
"if",
"err",
":=",
"iptablesRun",
"(",
"r",
".",
"AF",
",",
"string",
"(",
"r",
".",
"action",
")",
"+",
"\"",
"\"",
"+",
"r",
".",
"rule",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // iptablesAddRules installs the iptables rules for a given Vserver and Seesaw
// Cluster VIP. | [
"iptablesAddRules",
"installs",
"the",
"iptables",
"rules",
"for",
"a",
"given",
"Vserver",
"and",
"Seesaw",
"Cluster",
"VIP",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/iptables.go#L317-L328 | train |
google/seesaw | ncc/ipvs.go | initIPVS | func initIPVS() {
ipvsMutex.Lock()
defer ipvsMutex.Unlock()
log.Infof("Initialising IPVS...")
if err := ipvs.Init(); err != nil {
// TODO(jsing): modprobe ip_vs and try again.
log.Fatalf("IPVS initialisation failed: %v", err)
}
log.Infof("IPVS version %s", ipvs.Version())
} | go | func initIPVS() {
ipvsMutex.Lock()
defer ipvsMutex.Unlock()
log.Infof("Initialising IPVS...")
if err := ipvs.Init(); err != nil {
// TODO(jsing): modprobe ip_vs and try again.
log.Fatalf("IPVS initialisation failed: %v", err)
}
log.Infof("IPVS version %s", ipvs.Version())
} | [
"func",
"initIPVS",
"(",
")",
"{",
"ipvsMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"ipvsMutex",
".",
"Unlock",
"(",
")",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
":=",
"ipvs",
".",
"Init",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"// TODO(jsing): modprobe ip_vs and try again.",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"ipvs",
".",
"Version",
"(",
")",
")",
"\n",
"}"
] | // initIPVS initialises the IPVS sub-component. | [
"initIPVS",
"initialises",
"the",
"IPVS",
"sub",
"-",
"component",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ipvs.go#L34-L43 | train |
google/seesaw | ncc/ipvs.go | IPVSFlush | func (ncc *SeesawNCC) IPVSFlush(in int, out *int) error {
ipvsMutex.Lock()
defer ipvsMutex.Unlock()
return ipvs.Flush()
} | go | func (ncc *SeesawNCC) IPVSFlush(in int, out *int) error {
ipvsMutex.Lock()
defer ipvsMutex.Unlock()
return ipvs.Flush()
} | [
"func",
"(",
"ncc",
"*",
"SeesawNCC",
")",
"IPVSFlush",
"(",
"in",
"int",
",",
"out",
"*",
"int",
")",
"error",
"{",
"ipvsMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"ipvsMutex",
".",
"Unlock",
"(",
")",
"\n",
"return",
"ipvs",
".",
"Flush",
"(",
")",
"\n",
"}"
] | // IPVSFlush flushes all services and destinations from the IPVS table. | [
"IPVSFlush",
"flushes",
"all",
"services",
"and",
"destinations",
"from",
"the",
"IPVS",
"table",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ipvs.go#L46-L50 | train |
google/seesaw | ncc/ipvs.go | IPVSGetServices | func (ncc *SeesawNCC) IPVSGetServices(in int, s *ncctypes.IPVSServices) error {
ipvsMutex.Lock()
defer ipvsMutex.Unlock()
svcs, err := ipvs.GetServices()
if err != nil {
return err
}
s.Services = nil
for _, svc := range svcs {
s.Services = append(s.Services, svc)
}
return nil
} | go | func (ncc *SeesawNCC) IPVSGetServices(in int, s *ncctypes.IPVSServices) error {
ipvsMutex.Lock()
defer ipvsMutex.Unlock()
svcs, err := ipvs.GetServices()
if err != nil {
return err
}
s.Services = nil
for _, svc := range svcs {
s.Services = append(s.Services, svc)
}
return nil
} | [
"func",
"(",
"ncc",
"*",
"SeesawNCC",
")",
"IPVSGetServices",
"(",
"in",
"int",
",",
"s",
"*",
"ncctypes",
".",
"IPVSServices",
")",
"error",
"{",
"ipvsMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"ipvsMutex",
".",
"Unlock",
"(",
")",
"\n",
"svcs",
",",
"err",
":=",
"ipvs",
".",
"GetServices",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"s",
".",
"Services",
"=",
"nil",
"\n",
"for",
"_",
",",
"svc",
":=",
"range",
"svcs",
"{",
"s",
".",
"Services",
"=",
"append",
"(",
"s",
".",
"Services",
",",
"svc",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // IPVSGetServices gets the currently configured services from the IPVS table. | [
"IPVSGetServices",
"gets",
"the",
"currently",
"configured",
"services",
"from",
"the",
"IPVS",
"table",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ipvs.go#L53-L65 | train |
google/seesaw | ncc/ipvs.go | IPVSGetService | func (ncc *SeesawNCC) IPVSGetService(si *ipvs.Service, s *ncctypes.IPVSServices) error {
ipvsMutex.Lock()
defer ipvsMutex.Unlock()
so, err := ipvs.GetService(si)
if err != nil {
return err
}
s.Services = []*ipvs.Service{so}
return nil
} | go | func (ncc *SeesawNCC) IPVSGetService(si *ipvs.Service, s *ncctypes.IPVSServices) error {
ipvsMutex.Lock()
defer ipvsMutex.Unlock()
so, err := ipvs.GetService(si)
if err != nil {
return err
}
s.Services = []*ipvs.Service{so}
return nil
} | [
"func",
"(",
"ncc",
"*",
"SeesawNCC",
")",
"IPVSGetService",
"(",
"si",
"*",
"ipvs",
".",
"Service",
",",
"s",
"*",
"ncctypes",
".",
"IPVSServices",
")",
"error",
"{",
"ipvsMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"ipvsMutex",
".",
"Unlock",
"(",
")",
"\n",
"so",
",",
"err",
":=",
"ipvs",
".",
"GetService",
"(",
"si",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"s",
".",
"Services",
"=",
"[",
"]",
"*",
"ipvs",
".",
"Service",
"{",
"so",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // IPVSGetService gets the currently configured service from the IPVS table,
// which matches the specified service. | [
"IPVSGetService",
"gets",
"the",
"currently",
"configured",
"service",
"from",
"the",
"IPVS",
"table",
"which",
"matches",
"the",
"specified",
"service",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ipvs.go#L69-L78 | train |
google/seesaw | ncc/ipvs.go | IPVSAddService | func (ncc *SeesawNCC) IPVSAddService(svc *ipvs.Service, out *int) error {
ipvsMutex.Lock()
defer ipvsMutex.Unlock()
return ipvs.AddService(*svc)
} | go | func (ncc *SeesawNCC) IPVSAddService(svc *ipvs.Service, out *int) error {
ipvsMutex.Lock()
defer ipvsMutex.Unlock()
return ipvs.AddService(*svc)
} | [
"func",
"(",
"ncc",
"*",
"SeesawNCC",
")",
"IPVSAddService",
"(",
"svc",
"*",
"ipvs",
".",
"Service",
",",
"out",
"*",
"int",
")",
"error",
"{",
"ipvsMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"ipvsMutex",
".",
"Unlock",
"(",
")",
"\n",
"return",
"ipvs",
".",
"AddService",
"(",
"*",
"svc",
")",
"\n",
"}"
] | // IPVSAddService adds the specified service to the IPVS table. | [
"IPVSAddService",
"adds",
"the",
"specified",
"service",
"to",
"the",
"IPVS",
"table",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ipvs.go#L81-L85 | train |
google/seesaw | ncc/ipvs.go | IPVSUpdateService | func (ncc *SeesawNCC) IPVSUpdateService(svc *ipvs.Service, out *int) error {
ipvsMutex.Lock()
defer ipvsMutex.Unlock()
return ipvs.UpdateService(*svc)
} | go | func (ncc *SeesawNCC) IPVSUpdateService(svc *ipvs.Service, out *int) error {
ipvsMutex.Lock()
defer ipvsMutex.Unlock()
return ipvs.UpdateService(*svc)
} | [
"func",
"(",
"ncc",
"*",
"SeesawNCC",
")",
"IPVSUpdateService",
"(",
"svc",
"*",
"ipvs",
".",
"Service",
",",
"out",
"*",
"int",
")",
"error",
"{",
"ipvsMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"ipvsMutex",
".",
"Unlock",
"(",
")",
"\n",
"return",
"ipvs",
".",
"UpdateService",
"(",
"*",
"svc",
")",
"\n",
"}"
] | // IPVSUpdateService updates the specified service in the IPVS table. | [
"IPVSUpdateService",
"updates",
"the",
"specified",
"service",
"in",
"the",
"IPVS",
"table",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ipvs.go#L88-L92 | train |
google/seesaw | ncc/ipvs.go | IPVSDeleteService | func (ncc *SeesawNCC) IPVSDeleteService(svc *ipvs.Service, out *int) error {
ipvsMutex.Lock()
defer ipvsMutex.Unlock()
return ipvs.DeleteService(*svc)
} | go | func (ncc *SeesawNCC) IPVSDeleteService(svc *ipvs.Service, out *int) error {
ipvsMutex.Lock()
defer ipvsMutex.Unlock()
return ipvs.DeleteService(*svc)
} | [
"func",
"(",
"ncc",
"*",
"SeesawNCC",
")",
"IPVSDeleteService",
"(",
"svc",
"*",
"ipvs",
".",
"Service",
",",
"out",
"*",
"int",
")",
"error",
"{",
"ipvsMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"ipvsMutex",
".",
"Unlock",
"(",
")",
"\n",
"return",
"ipvs",
".",
"DeleteService",
"(",
"*",
"svc",
")",
"\n",
"}"
] | // IPVSDeleteService deletes the specified service from the IPVS table. | [
"IPVSDeleteService",
"deletes",
"the",
"specified",
"service",
"from",
"the",
"IPVS",
"table",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ipvs.go#L95-L99 | train |
google/seesaw | ncc/ipvs.go | IPVSAddDestination | func (ncc *SeesawNCC) IPVSAddDestination(dst *ncctypes.IPVSDestination, out *int) error {
ipvsMutex.Lock()
defer ipvsMutex.Unlock()
return ipvs.AddDestination(*dst.Service, *dst.Destination)
} | go | func (ncc *SeesawNCC) IPVSAddDestination(dst *ncctypes.IPVSDestination, out *int) error {
ipvsMutex.Lock()
defer ipvsMutex.Unlock()
return ipvs.AddDestination(*dst.Service, *dst.Destination)
} | [
"func",
"(",
"ncc",
"*",
"SeesawNCC",
")",
"IPVSAddDestination",
"(",
"dst",
"*",
"ncctypes",
".",
"IPVSDestination",
",",
"out",
"*",
"int",
")",
"error",
"{",
"ipvsMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"ipvsMutex",
".",
"Unlock",
"(",
")",
"\n",
"return",
"ipvs",
".",
"AddDestination",
"(",
"*",
"dst",
".",
"Service",
",",
"*",
"dst",
".",
"Destination",
")",
"\n",
"}"
] | // IPVSAddDestination adds the specified destination to the IPVS table. | [
"IPVSAddDestination",
"adds",
"the",
"specified",
"destination",
"to",
"the",
"IPVS",
"table",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ipvs.go#L102-L106 | train |
google/seesaw | ncc/ipvs.go | IPVSUpdateDestination | func (ncc *SeesawNCC) IPVSUpdateDestination(dst *ncctypes.IPVSDestination, out *int) error {
ipvsMutex.Lock()
defer ipvsMutex.Unlock()
return ipvs.UpdateDestination(*dst.Service, *dst.Destination)
} | go | func (ncc *SeesawNCC) IPVSUpdateDestination(dst *ncctypes.IPVSDestination, out *int) error {
ipvsMutex.Lock()
defer ipvsMutex.Unlock()
return ipvs.UpdateDestination(*dst.Service, *dst.Destination)
} | [
"func",
"(",
"ncc",
"*",
"SeesawNCC",
")",
"IPVSUpdateDestination",
"(",
"dst",
"*",
"ncctypes",
".",
"IPVSDestination",
",",
"out",
"*",
"int",
")",
"error",
"{",
"ipvsMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"ipvsMutex",
".",
"Unlock",
"(",
")",
"\n",
"return",
"ipvs",
".",
"UpdateDestination",
"(",
"*",
"dst",
".",
"Service",
",",
"*",
"dst",
".",
"Destination",
")",
"\n",
"}"
] | // IPVSUpdateDestination updates the specified destination in the IPVS table. | [
"IPVSUpdateDestination",
"updates",
"the",
"specified",
"destination",
"in",
"the",
"IPVS",
"table",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ipvs.go#L109-L113 | train |
google/seesaw | ncc/ipvs.go | IPVSDeleteDestination | func (ncc *SeesawNCC) IPVSDeleteDestination(dst *ncctypes.IPVSDestination, out *int) error {
ipvsMutex.Lock()
defer ipvsMutex.Unlock()
return ipvs.DeleteDestination(*dst.Service, *dst.Destination)
} | go | func (ncc *SeesawNCC) IPVSDeleteDestination(dst *ncctypes.IPVSDestination, out *int) error {
ipvsMutex.Lock()
defer ipvsMutex.Unlock()
return ipvs.DeleteDestination(*dst.Service, *dst.Destination)
} | [
"func",
"(",
"ncc",
"*",
"SeesawNCC",
")",
"IPVSDeleteDestination",
"(",
"dst",
"*",
"ncctypes",
".",
"IPVSDestination",
",",
"out",
"*",
"int",
")",
"error",
"{",
"ipvsMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"ipvsMutex",
".",
"Unlock",
"(",
")",
"\n",
"return",
"ipvs",
".",
"DeleteDestination",
"(",
"*",
"dst",
".",
"Service",
",",
"*",
"dst",
".",
"Destination",
")",
"\n",
"}"
] | // IPVSDeleteDestination deletes the specified destination from the IPVS table. | [
"IPVSDeleteDestination",
"deletes",
"the",
"specified",
"destination",
"from",
"the",
"IPVS",
"table",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ipvs.go#L116-L120 | train |
google/seesaw | common/seesaw/util.go | Copy | func (n *Node) Copy(c *Node) {
n.State = c.State
n.Priority = c.Priority
n.Host.Copy(&c.Host)
n.VserversEnabled = c.VserversEnabled
} | go | func (n *Node) Copy(c *Node) {
n.State = c.State
n.Priority = c.Priority
n.Host.Copy(&c.Host)
n.VserversEnabled = c.VserversEnabled
} | [
"func",
"(",
"n",
"*",
"Node",
")",
"Copy",
"(",
"c",
"*",
"Node",
")",
"{",
"n",
".",
"State",
"=",
"c",
".",
"State",
"\n",
"n",
".",
"Priority",
"=",
"c",
".",
"Priority",
"\n",
"n",
".",
"Host",
".",
"Copy",
"(",
"&",
"c",
".",
"Host",
")",
"\n",
"n",
".",
"VserversEnabled",
"=",
"c",
".",
"VserversEnabled",
"\n",
"}"
] | // Copy deep copies from the given Seesaw Node. | [
"Copy",
"deep",
"copies",
"from",
"the",
"given",
"Seesaw",
"Node",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L38-L43 | train |
google/seesaw | common/seesaw/util.go | Clone | func (n *Node) Clone() *Node {
var c Node
c.Copy(n)
return &c
} | go | func (n *Node) Clone() *Node {
var c Node
c.Copy(n)
return &c
} | [
"func",
"(",
"n",
"*",
"Node",
")",
"Clone",
"(",
")",
"*",
"Node",
"{",
"var",
"c",
"Node",
"\n",
"c",
".",
"Copy",
"(",
"n",
")",
"\n",
"return",
"&",
"c",
"\n",
"}"
] | // Clone creates an identical copy of the given Seesaw Node. | [
"Clone",
"creates",
"an",
"identical",
"copy",
"of",
"the",
"given",
"Seesaw",
"Node",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L46-L50 | train |
google/seesaw | common/seesaw/util.go | Copy | func (h *Host) Copy(c *Host) {
h.Hostname = c.Hostname
h.IPv4Addr = copyIP(c.IPv4Addr)
h.IPv4Mask = copyIPMask(c.IPv4Mask)
h.IPv6Addr = copyIP(c.IPv6Addr)
h.IPv6Mask = copyIPMask(c.IPv6Mask)
} | go | func (h *Host) Copy(c *Host) {
h.Hostname = c.Hostname
h.IPv4Addr = copyIP(c.IPv4Addr)
h.IPv4Mask = copyIPMask(c.IPv4Mask)
h.IPv6Addr = copyIP(c.IPv6Addr)
h.IPv6Mask = copyIPMask(c.IPv6Mask)
} | [
"func",
"(",
"h",
"*",
"Host",
")",
"Copy",
"(",
"c",
"*",
"Host",
")",
"{",
"h",
".",
"Hostname",
"=",
"c",
".",
"Hostname",
"\n",
"h",
".",
"IPv4Addr",
"=",
"copyIP",
"(",
"c",
".",
"IPv4Addr",
")",
"\n",
"h",
".",
"IPv4Mask",
"=",
"copyIPMask",
"(",
"c",
".",
"IPv4Mask",
")",
"\n",
"h",
".",
"IPv6Addr",
"=",
"copyIP",
"(",
"c",
".",
"IPv6Addr",
")",
"\n",
"h",
".",
"IPv6Mask",
"=",
"copyIPMask",
"(",
"c",
".",
"IPv6Mask",
")",
"\n",
"}"
] | // Copy deep copies from the given Seesaw Host. | [
"Copy",
"deep",
"copies",
"from",
"the",
"given",
"Seesaw",
"Host",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L75-L81 | train |
google/seesaw | common/seesaw/util.go | Clone | func (h *Host) Clone() *Host {
var c Host
c.Copy(h)
return &c
} | go | func (h *Host) Clone() *Host {
var c Host
c.Copy(h)
return &c
} | [
"func",
"(",
"h",
"*",
"Host",
")",
"Clone",
"(",
")",
"*",
"Host",
"{",
"var",
"c",
"Host",
"\n",
"c",
".",
"Copy",
"(",
"h",
")",
"\n",
"return",
"&",
"c",
"\n",
"}"
] | // Clone creates an identical copy of the given Seesaw Host. | [
"Clone",
"creates",
"an",
"identical",
"copy",
"of",
"the",
"given",
"Seesaw",
"Host",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L84-L88 | train |
google/seesaw | common/seesaw/util.go | Equal | func (h *Host) Equal(other *Host) bool {
return reflect.DeepEqual(h, other)
} | go | func (h *Host) Equal(other *Host) bool {
return reflect.DeepEqual(h, other)
} | [
"func",
"(",
"h",
"*",
"Host",
")",
"Equal",
"(",
"other",
"*",
"Host",
")",
"bool",
"{",
"return",
"reflect",
".",
"DeepEqual",
"(",
"h",
",",
"other",
")",
"\n",
"}"
] | // Equal returns whether two hosts are equal. | [
"Equal",
"returns",
"whether",
"two",
"hosts",
"are",
"equal",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L91-L93 | train |
google/seesaw | common/seesaw/util.go | IPv4Net | func (h *Host) IPv4Net() *net.IPNet {
return &net.IPNet{IP: h.IPv4Addr, Mask: h.IPv4Mask}
} | go | func (h *Host) IPv4Net() *net.IPNet {
return &net.IPNet{IP: h.IPv4Addr, Mask: h.IPv4Mask}
} | [
"func",
"(",
"h",
"*",
"Host",
")",
"IPv4Net",
"(",
")",
"*",
"net",
".",
"IPNet",
"{",
"return",
"&",
"net",
".",
"IPNet",
"{",
"IP",
":",
"h",
".",
"IPv4Addr",
",",
"Mask",
":",
"h",
".",
"IPv4Mask",
"}",
"\n",
"}"
] | // IPv4Net returns a net.IPNet for the host's IPv4 address. | [
"IPv4Net",
"returns",
"a",
"net",
".",
"IPNet",
"for",
"the",
"host",
"s",
"IPv4",
"address",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L96-L98 | train |
google/seesaw | common/seesaw/util.go | IPv6Net | func (h *Host) IPv6Net() *net.IPNet {
return &net.IPNet{IP: h.IPv6Addr, Mask: h.IPv6Mask}
} | go | func (h *Host) IPv6Net() *net.IPNet {
return &net.IPNet{IP: h.IPv6Addr, Mask: h.IPv6Mask}
} | [
"func",
"(",
"h",
"*",
"Host",
")",
"IPv6Net",
"(",
")",
"*",
"net",
".",
"IPNet",
"{",
"return",
"&",
"net",
".",
"IPNet",
"{",
"IP",
":",
"h",
".",
"IPv6Addr",
",",
"Mask",
":",
"h",
".",
"IPv6Mask",
"}",
"\n",
"}"
] | // IPv6Net returns a net.IPNet for the host's IPv6 address. | [
"IPv6Net",
"returns",
"a",
"net",
".",
"IPNet",
"for",
"the",
"host",
"s",
"IPv6",
"address",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L101-L103 | train |
google/seesaw | common/seesaw/util.go | IPv4Printable | func (h *Host) IPv4Printable() string {
if h.IPv4Addr == nil {
return "<not configured>"
}
return h.IPv4Net().String()
} | go | func (h *Host) IPv4Printable() string {
if h.IPv4Addr == nil {
return "<not configured>"
}
return h.IPv4Net().String()
} | [
"func",
"(",
"h",
"*",
"Host",
")",
"IPv4Printable",
"(",
")",
"string",
"{",
"if",
"h",
".",
"IPv4Addr",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"h",
".",
"IPv4Net",
"(",
")",
".",
"String",
"(",
")",
"\n",
"}"
] | // IPv4Printable returns a printable representation of the host's IPv4 address. | [
"IPv4Printable",
"returns",
"a",
"printable",
"representation",
"of",
"the",
"host",
"s",
"IPv4",
"address",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L106-L111 | train |
google/seesaw | common/seesaw/util.go | IPv6Printable | func (h *Host) IPv6Printable() string {
if h.IPv6Addr == nil {
return "<not configured>"
}
return h.IPv6Net().String()
} | go | func (h *Host) IPv6Printable() string {
if h.IPv6Addr == nil {
return "<not configured>"
}
return h.IPv6Net().String()
} | [
"func",
"(",
"h",
"*",
"Host",
")",
"IPv6Printable",
"(",
")",
"string",
"{",
"if",
"h",
".",
"IPv6Addr",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"h",
".",
"IPv6Net",
"(",
")",
".",
"String",
"(",
")",
"\n",
"}"
] | // IPv6Printable returns a printable representation of the host's IPv4 address. | [
"IPv6Printable",
"returns",
"a",
"printable",
"representation",
"of",
"the",
"host",
"s",
"IPv4",
"address",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L114-L119 | train |
google/seesaw | common/seesaw/util.go | Copy | func (b *Backend) Copy(c *Backend) {
b.Enabled = c.Enabled
b.InService = c.InService
b.Weight = c.Weight
b.Host.Copy(&c.Host)
} | go | func (b *Backend) Copy(c *Backend) {
b.Enabled = c.Enabled
b.InService = c.InService
b.Weight = c.Weight
b.Host.Copy(&c.Host)
} | [
"func",
"(",
"b",
"*",
"Backend",
")",
"Copy",
"(",
"c",
"*",
"Backend",
")",
"{",
"b",
".",
"Enabled",
"=",
"c",
".",
"Enabled",
"\n",
"b",
".",
"InService",
"=",
"c",
".",
"InService",
"\n",
"b",
".",
"Weight",
"=",
"c",
".",
"Weight",
"\n",
"b",
".",
"Host",
".",
"Copy",
"(",
"&",
"c",
".",
"Host",
")",
"\n",
"}"
] | // Copy deep copies from the given Seesaw Backend. | [
"Copy",
"deep",
"copies",
"from",
"the",
"given",
"Seesaw",
"Backend",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L122-L127 | train |
google/seesaw | common/seesaw/util.go | Clone | func (b *Backend) Clone() *Backend {
var c Backend
c.Copy(b)
return &c
} | go | func (b *Backend) Clone() *Backend {
var c Backend
c.Copy(b)
return &c
} | [
"func",
"(",
"b",
"*",
"Backend",
")",
"Clone",
"(",
")",
"*",
"Backend",
"{",
"var",
"c",
"Backend",
"\n",
"c",
".",
"Copy",
"(",
"b",
")",
"\n",
"return",
"&",
"c",
"\n",
"}"
] | // Clone creates an identical copy of the given Seesaw Backend. | [
"Clone",
"creates",
"an",
"identical",
"copy",
"of",
"the",
"given",
"Seesaw",
"Backend",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L130-L134 | train |
google/seesaw | common/seesaw/util.go | Copy | func (h *HAConfig) Copy(c *HAConfig) {
h.Enabled = c.Enabled
h.LocalAddr = copyIP(c.LocalAddr)
h.RemoteAddr = copyIP(c.RemoteAddr)
h.Priority = c.Priority
h.VRID = c.VRID
} | go | func (h *HAConfig) Copy(c *HAConfig) {
h.Enabled = c.Enabled
h.LocalAddr = copyIP(c.LocalAddr)
h.RemoteAddr = copyIP(c.RemoteAddr)
h.Priority = c.Priority
h.VRID = c.VRID
} | [
"func",
"(",
"h",
"*",
"HAConfig",
")",
"Copy",
"(",
"c",
"*",
"HAConfig",
")",
"{",
"h",
".",
"Enabled",
"=",
"c",
".",
"Enabled",
"\n",
"h",
".",
"LocalAddr",
"=",
"copyIP",
"(",
"c",
".",
"LocalAddr",
")",
"\n",
"h",
".",
"RemoteAddr",
"=",
"copyIP",
"(",
"c",
".",
"RemoteAddr",
")",
"\n",
"h",
".",
"Priority",
"=",
"c",
".",
"Priority",
"\n",
"h",
".",
"VRID",
"=",
"c",
".",
"VRID",
"\n",
"}"
] | // Copy deep copies from the given Seesaw HAConfig. | [
"Copy",
"deep",
"copies",
"from",
"the",
"given",
"Seesaw",
"HAConfig",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L142-L148 | train |
google/seesaw | common/seesaw/util.go | Clone | func (h *HAConfig) Clone() *HAConfig {
var c HAConfig
c.Copy(h)
return &c
} | go | func (h *HAConfig) Clone() *HAConfig {
var c HAConfig
c.Copy(h)
return &c
} | [
"func",
"(",
"h",
"*",
"HAConfig",
")",
"Clone",
"(",
")",
"*",
"HAConfig",
"{",
"var",
"c",
"HAConfig",
"\n",
"c",
".",
"Copy",
"(",
"h",
")",
"\n",
"return",
"&",
"c",
"\n",
"}"
] | // Clone creates an identical copy of the given Seesaw HAConfig. | [
"Clone",
"creates",
"an",
"identical",
"copy",
"of",
"the",
"given",
"Seesaw",
"HAConfig",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L151-L155 | train |
google/seesaw | common/seesaw/util.go | Equal | func (h *HAConfig) Equal(other *HAConfig) bool {
return h.Enabled == other.Enabled &&
h.LocalAddr.Equal(other.LocalAddr) &&
h.RemoteAddr.Equal(other.RemoteAddr) &&
h.Priority == other.Priority &&
h.VRID == other.VRID
} | go | func (h *HAConfig) Equal(other *HAConfig) bool {
return h.Enabled == other.Enabled &&
h.LocalAddr.Equal(other.LocalAddr) &&
h.RemoteAddr.Equal(other.RemoteAddr) &&
h.Priority == other.Priority &&
h.VRID == other.VRID
} | [
"func",
"(",
"h",
"*",
"HAConfig",
")",
"Equal",
"(",
"other",
"*",
"HAConfig",
")",
"bool",
"{",
"return",
"h",
".",
"Enabled",
"==",
"other",
".",
"Enabled",
"&&",
"h",
".",
"LocalAddr",
".",
"Equal",
"(",
"other",
".",
"LocalAddr",
")",
"&&",
"h",
".",
"RemoteAddr",
".",
"Equal",
"(",
"other",
".",
"RemoteAddr",
")",
"&&",
"h",
".",
"Priority",
"==",
"other",
".",
"Priority",
"&&",
"h",
".",
"VRID",
"==",
"other",
".",
"VRID",
"\n",
"}"
] | // Equal reports whether this HAConfig is equal to the given HAConfig. | [
"Equal",
"reports",
"whether",
"this",
"HAConfig",
"is",
"equal",
"to",
"the",
"given",
"HAConfig",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L158-L164 | train |
google/seesaw | common/seesaw/util.go | String | func (h HAConfig) String() string {
return fmt.Sprintf("Enabled: %v, LocalAddr: %v, RemoteAddr: %v, Priority: %d, VRID: %d",
h.Enabled, h.LocalAddr, h.RemoteAddr, h.Priority, h.VRID)
} | go | func (h HAConfig) String() string {
return fmt.Sprintf("Enabled: %v, LocalAddr: %v, RemoteAddr: %v, Priority: %d, VRID: %d",
h.Enabled, h.LocalAddr, h.RemoteAddr, h.Priority, h.VRID)
} | [
"func",
"(",
"h",
"HAConfig",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"h",
".",
"Enabled",
",",
"h",
".",
"LocalAddr",
",",
"h",
".",
"RemoteAddr",
",",
"h",
".",
"Priority",
",",
"h",
".",
"VRID",
")",
"\n",
"}"
] | // String returns the string representation of an HAConfig. | [
"String",
"returns",
"the",
"string",
"representation",
"of",
"an",
"HAConfig",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L167-L170 | train |
google/seesaw | common/seesaw/util.go | String | func (h HAState) String() string {
switch h {
case HAUnknown:
return "Unknown"
case HABackup:
return "Backup"
case HADisabled:
return "Disabled"
case HAError:
return "Error"
case HAMaster:
return "Master"
case HAShutdown:
return "Shutdown"
}
return "(invalid)"
} | go | func (h HAState) String() string {
switch h {
case HAUnknown:
return "Unknown"
case HABackup:
return "Backup"
case HADisabled:
return "Disabled"
case HAError:
return "Error"
case HAMaster:
return "Master"
case HAShutdown:
return "Shutdown"
}
return "(invalid)"
} | [
"func",
"(",
"h",
"HAState",
")",
"String",
"(",
")",
"string",
"{",
"switch",
"h",
"{",
"case",
"HAUnknown",
":",
"return",
"\"",
"\"",
"\n",
"case",
"HABackup",
":",
"return",
"\"",
"\"",
"\n",
"case",
"HADisabled",
":",
"return",
"\"",
"\"",
"\n",
"case",
"HAError",
":",
"return",
"\"",
"\"",
"\n",
"case",
"HAMaster",
":",
"return",
"\"",
"\"",
"\n",
"case",
"HAShutdown",
":",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
] | // String returns the string representation of an HAState. | [
"String",
"returns",
"the",
"string",
"representation",
"of",
"an",
"HAState",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L173-L189 | train |
google/seesaw | common/seesaw/util.go | Equal | func (v *VLAN) Equal(other *VLAN) bool {
// Exclude backend and VIP counters from comparison.
return v.ID == other.ID && v.Host.Equal(&other.Host)
} | go | func (v *VLAN) Equal(other *VLAN) bool {
// Exclude backend and VIP counters from comparison.
return v.ID == other.ID && v.Host.Equal(&other.Host)
} | [
"func",
"(",
"v",
"*",
"VLAN",
")",
"Equal",
"(",
"other",
"*",
"VLAN",
")",
"bool",
"{",
"// Exclude backend and VIP counters from comparison.",
"return",
"v",
".",
"ID",
"==",
"other",
".",
"ID",
"&&",
"v",
".",
"Host",
".",
"Equal",
"(",
"&",
"other",
".",
"Host",
")",
"\n",
"}"
] | // Equal reports whether this VLAN is equal to the given VLAN. | [
"Equal",
"reports",
"whether",
"this",
"VLAN",
"is",
"equal",
"to",
"the",
"given",
"VLAN",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L192-L195 | train |
google/seesaw | common/seesaw/util.go | String | func (v *VLAN) String() string {
return fmt.Sprintf("{ID=%d, Host=%s, IPv4=%s, IPv6=%s}", v.ID, v.Hostname, v.IPv4Printable(), v.IPv6Printable())
} | go | func (v *VLAN) String() string {
return fmt.Sprintf("{ID=%d, Host=%s, IPv4=%s, IPv6=%s}", v.ID, v.Hostname, v.IPv4Printable(), v.IPv6Printable())
} | [
"func",
"(",
"v",
"*",
"VLAN",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"v",
".",
"ID",
",",
"v",
".",
"Hostname",
",",
"v",
".",
"IPv4Printable",
"(",
")",
",",
"v",
".",
"IPv6Printable",
"(",
")",
")",
"\n",
"}"
] | // String returns the string representation of a VLAN. | [
"String",
"returns",
"the",
"string",
"representation",
"of",
"a",
"VLAN",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L203-L205 | train |
google/seesaw | common/seesaw/util.go | String | func (sk ServiceKey) String() string {
return fmt.Sprintf("%s %s %d", sk.AF, sk.Proto, sk.Port)
} | go | func (sk ServiceKey) String() string {
return fmt.Sprintf("%s %s %d", sk.AF, sk.Proto, sk.Port)
} | [
"func",
"(",
"sk",
"ServiceKey",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"sk",
".",
"AF",
",",
"sk",
".",
"Proto",
",",
"sk",
".",
"Port",
")",
"\n",
"}"
] | // String returns the string representation of a ServiceKey. | [
"String",
"returns",
"the",
"string",
"representation",
"of",
"a",
"ServiceKey",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L218-L220 | train |
google/seesaw | common/seesaw/util.go | IP | func (d *Destination) IP(af AF) net.IP {
switch af {
case IPv4:
return d.Backend.IPv4Addr
case IPv6:
return d.Backend.IPv6Addr
}
return nil
} | go | func (d *Destination) IP(af AF) net.IP {
switch af {
case IPv4:
return d.Backend.IPv4Addr
case IPv6:
return d.Backend.IPv6Addr
}
return nil
} | [
"func",
"(",
"d",
"*",
"Destination",
")",
"IP",
"(",
"af",
"AF",
")",
"net",
".",
"IP",
"{",
"switch",
"af",
"{",
"case",
"IPv4",
":",
"return",
"d",
".",
"Backend",
".",
"IPv4Addr",
"\n",
"case",
"IPv6",
":",
"return",
"d",
".",
"Backend",
".",
"IPv6Addr",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // IP returns the destination IP address for a given address family. | [
"IP",
"returns",
"the",
"destination",
"IP",
"address",
"for",
"a",
"given",
"address",
"family",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L244-L252 | train |
google/seesaw | common/seesaw/util.go | copyIP | func copyIP(src net.IP) net.IP {
return net.IP(copyBytes(src))
} | go | func copyIP(src net.IP) net.IP {
return net.IP(copyBytes(src))
} | [
"func",
"copyIP",
"(",
"src",
"net",
".",
"IP",
")",
"net",
".",
"IP",
"{",
"return",
"net",
".",
"IP",
"(",
"copyBytes",
"(",
"src",
")",
")",
"\n",
"}"
] | // copyIP creates a copy of an IP. | [
"copyIP",
"creates",
"a",
"copy",
"of",
"an",
"IP",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L262-L264 | train |
google/seesaw | common/seesaw/util.go | copyIPMask | func copyIPMask(src net.IPMask) net.IPMask {
return net.IPMask(copyBytes(src))
} | go | func copyIPMask(src net.IPMask) net.IPMask {
return net.IPMask(copyBytes(src))
} | [
"func",
"copyIPMask",
"(",
"src",
"net",
".",
"IPMask",
")",
"net",
".",
"IPMask",
"{",
"return",
"net",
".",
"IPMask",
"(",
"copyBytes",
"(",
"src",
")",
")",
"\n",
"}"
] | // copyIPMask creates a copy of an IPMask. | [
"copyIPMask",
"creates",
"a",
"copy",
"of",
"an",
"IPMask",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L267-L269 | train |
google/seesaw | common/seesaw/util.go | copyBytes | func copyBytes(src []byte) []byte {
if src == nil {
return nil
}
dst := make([]byte, len(src))
copy(dst, src)
return dst
} | go | func copyBytes(src []byte) []byte {
if src == nil {
return nil
}
dst := make([]byte, len(src))
copy(dst, src)
return dst
} | [
"func",
"copyBytes",
"(",
"src",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"if",
"src",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"dst",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"len",
"(",
"src",
")",
")",
"\n",
"copy",
"(",
"dst",
",",
"src",
")",
"\n",
"return",
"dst",
"\n",
"}"
] | // copyBytes creates a copy of a byte slice. | [
"copyBytes",
"creates",
"a",
"copy",
"of",
"a",
"byte",
"slice",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L272-L279 | train |
google/seesaw | common/seesaw/util.go | IsAnycast | func IsAnycast(ip net.IP) bool {
return netIPv4Anycast.Contains(ip) || netIPv6Anycast.Contains(ip)
} | go | func IsAnycast(ip net.IP) bool {
return netIPv4Anycast.Contains(ip) || netIPv6Anycast.Contains(ip)
} | [
"func",
"IsAnycast",
"(",
"ip",
"net",
".",
"IP",
")",
"bool",
"{",
"return",
"netIPv4Anycast",
".",
"Contains",
"(",
"ip",
")",
"||",
"netIPv6Anycast",
".",
"Contains",
"(",
"ip",
")",
"\n",
"}"
] | // IsAnycast reports whether an IP address is an anycast address. | [
"IsAnycast",
"reports",
"whether",
"an",
"IP",
"address",
"is",
"an",
"anycast",
"address",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L282-L284 | train |
google/seesaw | common/seesaw/util.go | InSubnets | func InSubnets(ip net.IP, subnets map[string]*net.IPNet) bool {
for _, subnet := range subnets {
if subnet.Contains(ip) {
return true
}
}
return false
} | go | func InSubnets(ip net.IP, subnets map[string]*net.IPNet) bool {
for _, subnet := range subnets {
if subnet.Contains(ip) {
return true
}
}
return false
} | [
"func",
"InSubnets",
"(",
"ip",
"net",
".",
"IP",
",",
"subnets",
"map",
"[",
"string",
"]",
"*",
"net",
".",
"IPNet",
")",
"bool",
"{",
"for",
"_",
",",
"subnet",
":=",
"range",
"subnets",
"{",
"if",
"subnet",
".",
"Contains",
"(",
"ip",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // InSubnets reports whether an IP address is in one of a map of subnets. | [
"InSubnets",
"reports",
"whether",
"an",
"IP",
"address",
"is",
"in",
"one",
"of",
"a",
"map",
"of",
"subnets",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L287-L294 | train |
google/seesaw | engine/core.go | NewEngine | func NewEngine(cfg *config.EngineConfig) *Engine {
if cfg == nil {
defaultCfg := config.DefaultEngineConfig()
cfg = &defaultCfg
}
// TODO(jsing): Validate node, peer and cluster IP configuration.
engine := &Engine{
config: cfg,
fwmAlloc: newMarkAllocator(fwmAllocBase, fwmAllocSize),
ncc: ncclient.NewNCC(cfg.NCCSocket),
overrides: make(map[string]seesaw.Override),
overrideChan: make(chan seesaw.Override),
vlans: make(map[uint16]*seesaw.VLAN),
vservers: make(map[string]*vserver),
shutdown: make(chan bool),
shutdownARP: make(chan bool),
shutdownIPC: make(chan bool),
shutdownRPC: make(chan bool),
vserverSnapshots: make(map[string]*seesaw.Vserver),
vserverChan: make(chan *seesaw.Vserver, 1000),
}
engine.bgpManager = newBGPManager(engine, cfg.BGPUpdateInterval)
engine.haManager = newHAManager(engine, cfg.HAStateTimeout)
engine.hcManager = newHealthcheckManager(engine)
engine.syncClient = newSyncClient(engine)
engine.syncServer = newSyncServer(engine)
return engine
} | go | func NewEngine(cfg *config.EngineConfig) *Engine {
if cfg == nil {
defaultCfg := config.DefaultEngineConfig()
cfg = &defaultCfg
}
// TODO(jsing): Validate node, peer and cluster IP configuration.
engine := &Engine{
config: cfg,
fwmAlloc: newMarkAllocator(fwmAllocBase, fwmAllocSize),
ncc: ncclient.NewNCC(cfg.NCCSocket),
overrides: make(map[string]seesaw.Override),
overrideChan: make(chan seesaw.Override),
vlans: make(map[uint16]*seesaw.VLAN),
vservers: make(map[string]*vserver),
shutdown: make(chan bool),
shutdownARP: make(chan bool),
shutdownIPC: make(chan bool),
shutdownRPC: make(chan bool),
vserverSnapshots: make(map[string]*seesaw.Vserver),
vserverChan: make(chan *seesaw.Vserver, 1000),
}
engine.bgpManager = newBGPManager(engine, cfg.BGPUpdateInterval)
engine.haManager = newHAManager(engine, cfg.HAStateTimeout)
engine.hcManager = newHealthcheckManager(engine)
engine.syncClient = newSyncClient(engine)
engine.syncServer = newSyncServer(engine)
return engine
} | [
"func",
"NewEngine",
"(",
"cfg",
"*",
"config",
".",
"EngineConfig",
")",
"*",
"Engine",
"{",
"if",
"cfg",
"==",
"nil",
"{",
"defaultCfg",
":=",
"config",
".",
"DefaultEngineConfig",
"(",
")",
"\n",
"cfg",
"=",
"&",
"defaultCfg",
"\n",
"}",
"\n",
"// TODO(jsing): Validate node, peer and cluster IP configuration.",
"engine",
":=",
"&",
"Engine",
"{",
"config",
":",
"cfg",
",",
"fwmAlloc",
":",
"newMarkAllocator",
"(",
"fwmAllocBase",
",",
"fwmAllocSize",
")",
",",
"ncc",
":",
"ncclient",
".",
"NewNCC",
"(",
"cfg",
".",
"NCCSocket",
")",
",",
"overrides",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"seesaw",
".",
"Override",
")",
",",
"overrideChan",
":",
"make",
"(",
"chan",
"seesaw",
".",
"Override",
")",
",",
"vlans",
":",
"make",
"(",
"map",
"[",
"uint16",
"]",
"*",
"seesaw",
".",
"VLAN",
")",
",",
"vservers",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"vserver",
")",
",",
"shutdown",
":",
"make",
"(",
"chan",
"bool",
")",
",",
"shutdownARP",
":",
"make",
"(",
"chan",
"bool",
")",
",",
"shutdownIPC",
":",
"make",
"(",
"chan",
"bool",
")",
",",
"shutdownRPC",
":",
"make",
"(",
"chan",
"bool",
")",
",",
"vserverSnapshots",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"seesaw",
".",
"Vserver",
")",
",",
"vserverChan",
":",
"make",
"(",
"chan",
"*",
"seesaw",
".",
"Vserver",
",",
"1000",
")",
",",
"}",
"\n",
"engine",
".",
"bgpManager",
"=",
"newBGPManager",
"(",
"engine",
",",
"cfg",
".",
"BGPUpdateInterval",
")",
"\n",
"engine",
".",
"haManager",
"=",
"newHAManager",
"(",
"engine",
",",
"cfg",
".",
"HAStateTimeout",
")",
"\n",
"engine",
".",
"hcManager",
"=",
"newHealthcheckManager",
"(",
"engine",
")",
"\n",
"engine",
".",
"syncClient",
"=",
"newSyncClient",
"(",
"engine",
")",
"\n",
"engine",
".",
"syncServer",
"=",
"newSyncServer",
"(",
"engine",
")",
"\n",
"return",
"engine",
"\n",
"}"
] | // NewEngine returns an initialised Engine struct. | [
"NewEngine",
"returns",
"an",
"initialised",
"Engine",
"struct",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L86-L117 | train |
google/seesaw | engine/core.go | Run | func (e *Engine) Run() {
log.Infof("Seesaw Engine starting for %s", e.config.ClusterName)
e.initNetwork()
n, err := config.NewNotifier(e.config)
if err != nil {
log.Fatalf("config.NewNotifier() failed: %v", err)
}
e.notifier = n
if e.config.AnycastEnabled {
go e.bgpManager.run()
}
go e.hcManager.run()
go e.syncClient.run()
go e.syncServer.run()
go e.syncRPC()
go e.engineIPC()
go e.gratuitousARP()
e.manager()
} | go | func (e *Engine) Run() {
log.Infof("Seesaw Engine starting for %s", e.config.ClusterName)
e.initNetwork()
n, err := config.NewNotifier(e.config)
if err != nil {
log.Fatalf("config.NewNotifier() failed: %v", err)
}
e.notifier = n
if e.config.AnycastEnabled {
go e.bgpManager.run()
}
go e.hcManager.run()
go e.syncClient.run()
go e.syncServer.run()
go e.syncRPC()
go e.engineIPC()
go e.gratuitousARP()
e.manager()
} | [
"func",
"(",
"e",
"*",
"Engine",
")",
"Run",
"(",
")",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"e",
".",
"config",
".",
"ClusterName",
")",
"\n\n",
"e",
".",
"initNetwork",
"(",
")",
"\n\n",
"n",
",",
"err",
":=",
"config",
".",
"NewNotifier",
"(",
"e",
".",
"config",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"e",
".",
"notifier",
"=",
"n",
"\n\n",
"if",
"e",
".",
"config",
".",
"AnycastEnabled",
"{",
"go",
"e",
".",
"bgpManager",
".",
"run",
"(",
")",
"\n",
"}",
"\n",
"go",
"e",
".",
"hcManager",
".",
"run",
"(",
")",
"\n\n",
"go",
"e",
".",
"syncClient",
".",
"run",
"(",
")",
"\n",
"go",
"e",
".",
"syncServer",
".",
"run",
"(",
")",
"\n\n",
"go",
"e",
".",
"syncRPC",
"(",
")",
"\n",
"go",
"e",
".",
"engineIPC",
"(",
")",
"\n",
"go",
"e",
".",
"gratuitousARP",
"(",
")",
"\n\n",
"e",
".",
"manager",
"(",
")",
"\n",
"}"
] | // Run starts the Engine. | [
"Run",
"starts",
"the",
"Engine",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L120-L144 | train |
google/seesaw | engine/core.go | haStatus | func (e *Engine) haStatus() seesaw.HAStatus {
e.haManager.statusLock.RLock()
defer e.haManager.statusLock.RUnlock()
return e.haManager.status
} | go | func (e *Engine) haStatus() seesaw.HAStatus {
e.haManager.statusLock.RLock()
defer e.haManager.statusLock.RUnlock()
return e.haManager.status
} | [
"func",
"(",
"e",
"*",
"Engine",
")",
"haStatus",
"(",
")",
"seesaw",
".",
"HAStatus",
"{",
"e",
".",
"haManager",
".",
"statusLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"e",
".",
"haManager",
".",
"statusLock",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"e",
".",
"haManager",
".",
"status",
"\n",
"}"
] | // haStatus returns the current HA status from the engine. | [
"haStatus",
"returns",
"the",
"current",
"HA",
"status",
"from",
"the",
"engine",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L152-L156 | train |
google/seesaw | engine/core.go | setHAState | func (e *Engine) setHAState(state seesaw.HAState) {
e.haManager.stateChan <- state
} | go | func (e *Engine) setHAState(state seesaw.HAState) {
e.haManager.stateChan <- state
} | [
"func",
"(",
"e",
"*",
"Engine",
")",
"setHAState",
"(",
"state",
"seesaw",
".",
"HAState",
")",
"{",
"e",
".",
"haManager",
".",
"stateChan",
"<-",
"state",
"\n",
"}"
] | // setHAState tells the engine what its current HAState should be. | [
"setHAState",
"tells",
"the",
"engine",
"what",
"its",
"current",
"HAState",
"should",
"be",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L164-L166 | train |
google/seesaw | engine/core.go | setHAStatus | func (e *Engine) setHAStatus(status seesaw.HAStatus) {
e.haManager.statusChan <- status
} | go | func (e *Engine) setHAStatus(status seesaw.HAStatus) {
e.haManager.statusChan <- status
} | [
"func",
"(",
"e",
"*",
"Engine",
")",
"setHAStatus",
"(",
"status",
"seesaw",
".",
"HAStatus",
")",
"{",
"e",
".",
"haManager",
".",
"statusChan",
"<-",
"status",
"\n",
"}"
] | // setHAStatus tells the engine what the current HA status is. | [
"setHAStatus",
"tells",
"the",
"engine",
"what",
"the",
"current",
"HA",
"status",
"is",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L169-L171 | train |
google/seesaw | engine/core.go | haConfig | func (e *Engine) haConfig() (*seesaw.HAConfig, error) {
n, err := e.thisNode()
if err != nil {
return nil, err
}
// TODO(jsing): This does not allow for IPv6-only operation.
return &seesaw.HAConfig{
Enabled: n.State != seesaw.HADisabled,
LocalAddr: e.config.Node.IPv4Addr,
RemoteAddr: e.config.VRRPDestIP,
Priority: n.Priority,
VRID: e.config.VRID,
}, nil
} | go | func (e *Engine) haConfig() (*seesaw.HAConfig, error) {
n, err := e.thisNode()
if err != nil {
return nil, err
}
// TODO(jsing): This does not allow for IPv6-only operation.
return &seesaw.HAConfig{
Enabled: n.State != seesaw.HADisabled,
LocalAddr: e.config.Node.IPv4Addr,
RemoteAddr: e.config.VRRPDestIP,
Priority: n.Priority,
VRID: e.config.VRID,
}, nil
} | [
"func",
"(",
"e",
"*",
"Engine",
")",
"haConfig",
"(",
")",
"(",
"*",
"seesaw",
".",
"HAConfig",
",",
"error",
")",
"{",
"n",
",",
"err",
":=",
"e",
".",
"thisNode",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"// TODO(jsing): This does not allow for IPv6-only operation.",
"return",
"&",
"seesaw",
".",
"HAConfig",
"{",
"Enabled",
":",
"n",
".",
"State",
"!=",
"seesaw",
".",
"HADisabled",
",",
"LocalAddr",
":",
"e",
".",
"config",
".",
"Node",
".",
"IPv4Addr",
",",
"RemoteAddr",
":",
"e",
".",
"config",
".",
"VRRPDestIP",
",",
"Priority",
":",
"n",
".",
"Priority",
",",
"VRID",
":",
"e",
".",
"config",
".",
"VRID",
",",
"}",
",",
"nil",
"\n",
"}"
] | // haConfig returns the HAConfig for an engine. | [
"haConfig",
"returns",
"the",
"HAConfig",
"for",
"an",
"engine",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L174-L187 | train |
google/seesaw | engine/core.go | thisNode | func (e *Engine) thisNode() (*seesaw.Node, error) {
e.clusterLock.RLock()
c := e.cluster
e.clusterLock.RUnlock()
if c == nil {
return nil, fmt.Errorf("cluster configuration not loaded")
}
// TODO(jsing): This does not allow for IPv6-only operation.
ip := e.config.Node.IPv4Addr
for _, n := range c.Nodes {
if ip.Equal(n.IPv4Addr) {
return n, nil
}
}
return nil, fmt.Errorf("node %v not configured", ip)
} | go | func (e *Engine) thisNode() (*seesaw.Node, error) {
e.clusterLock.RLock()
c := e.cluster
e.clusterLock.RUnlock()
if c == nil {
return nil, fmt.Errorf("cluster configuration not loaded")
}
// TODO(jsing): This does not allow for IPv6-only operation.
ip := e.config.Node.IPv4Addr
for _, n := range c.Nodes {
if ip.Equal(n.IPv4Addr) {
return n, nil
}
}
return nil, fmt.Errorf("node %v not configured", ip)
} | [
"func",
"(",
"e",
"*",
"Engine",
")",
"thisNode",
"(",
")",
"(",
"*",
"seesaw",
".",
"Node",
",",
"error",
")",
"{",
"e",
".",
"clusterLock",
".",
"RLock",
"(",
")",
"\n",
"c",
":=",
"e",
".",
"cluster",
"\n",
"e",
".",
"clusterLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"if",
"c",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// TODO(jsing): This does not allow for IPv6-only operation.",
"ip",
":=",
"e",
".",
"config",
".",
"Node",
".",
"IPv4Addr",
"\n",
"for",
"_",
",",
"n",
":=",
"range",
"c",
".",
"Nodes",
"{",
"if",
"ip",
".",
"Equal",
"(",
"n",
".",
"IPv4Addr",
")",
"{",
"return",
"n",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ip",
")",
"\n",
"}"
] | // thisNode returns the Node for the machine on which this engine is running. | [
"thisNode",
"returns",
"the",
"Node",
"for",
"the",
"machine",
"on",
"which",
"this",
"engine",
"is",
"running",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L190-L206 | train |
google/seesaw | engine/core.go | engineIPC | func (e *Engine) engineIPC() {
if err := server.RemoveUnixSocket(e.config.SocketPath); err != nil {
log.Fatalf("Failed to remove socket: %v", err)
}
ln, err := net.Listen("unix", e.config.SocketPath)
if err != nil {
log.Fatalf("Listen failed: %v", err)
}
defer os.Remove(e.config.SocketPath)
seesawIPC := rpc.NewServer()
seesawIPC.Register(&SeesawEngine{e})
go server.RPCAccept(ln, seesawIPC)
<-e.shutdownIPC
ln.Close()
e.shutdownIPC <- true
} | go | func (e *Engine) engineIPC() {
if err := server.RemoveUnixSocket(e.config.SocketPath); err != nil {
log.Fatalf("Failed to remove socket: %v", err)
}
ln, err := net.Listen("unix", e.config.SocketPath)
if err != nil {
log.Fatalf("Listen failed: %v", err)
}
defer os.Remove(e.config.SocketPath)
seesawIPC := rpc.NewServer()
seesawIPC.Register(&SeesawEngine{e})
go server.RPCAccept(ln, seesawIPC)
<-e.shutdownIPC
ln.Close()
e.shutdownIPC <- true
} | [
"func",
"(",
"e",
"*",
"Engine",
")",
"engineIPC",
"(",
")",
"{",
"if",
"err",
":=",
"server",
".",
"RemoveUnixSocket",
"(",
"e",
".",
"config",
".",
"SocketPath",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"ln",
",",
"err",
":=",
"net",
".",
"Listen",
"(",
"\"",
"\"",
",",
"e",
".",
"config",
".",
"SocketPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"os",
".",
"Remove",
"(",
"e",
".",
"config",
".",
"SocketPath",
")",
"\n\n",
"seesawIPC",
":=",
"rpc",
".",
"NewServer",
"(",
")",
"\n",
"seesawIPC",
".",
"Register",
"(",
"&",
"SeesawEngine",
"{",
"e",
"}",
")",
"\n",
"go",
"server",
".",
"RPCAccept",
"(",
"ln",
",",
"seesawIPC",
")",
"\n\n",
"<-",
"e",
".",
"shutdownIPC",
"\n",
"ln",
".",
"Close",
"(",
")",
"\n",
"e",
".",
"shutdownIPC",
"<-",
"true",
"\n",
"}"
] | // engineIPC starts an RPC server to handle IPC via a Unix Domain socket. | [
"engineIPC",
"starts",
"an",
"RPC",
"server",
"to",
"handle",
"IPC",
"via",
"a",
"Unix",
"Domain",
"socket",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L209-L226 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.