repo stringlengths 5 67 | path stringlengths 4 218 | func_name stringlengths 0 151 | original_string stringlengths 52 373k | language stringclasses 6 values | code stringlengths 52 373k | code_tokens listlengths 10 512 | docstring stringlengths 3 47.2k | docstring_tokens listlengths 3 234 | sha stringlengths 40 40 | url stringlengths 85 339 | partition stringclasses 3 values |
|---|---|---|---|---|---|---|---|---|---|---|---|
google/seesaw | healthcheck/core.go | sendBatch | func (s *Server) sendBatch(batch []*Notification) error {
engineConn, err := net.DialTimeout("unix", s.config.EngineSocket, engineTimeout)
if err != nil {
return err
}
engineConn.SetDeadline(time.Now().Add(engineTimeout))
engine := rpc.NewClient(engineConn)
defer engine.Close()
var reply int
ctx := ipc.NewTrustedContext(seesaw.SCHealthcheck)
return engine.Call("SeesawEngine.HealthState", &HealthState{ctx, batch}, &reply)
} | go | func (s *Server) sendBatch(batch []*Notification) error {
engineConn, err := net.DialTimeout("unix", s.config.EngineSocket, engineTimeout)
if err != nil {
return err
}
engineConn.SetDeadline(time.Now().Add(engineTimeout))
engine := rpc.NewClient(engineConn)
defer engine.Close()
var reply int
ctx := ipc.NewTrustedContext(seesaw.SCHealthcheck)
return engine.Call("SeesawEngine.HealthState", &HealthState{ctx, batch}, &reply)
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"sendBatch",
"(",
"batch",
"[",
"]",
"*",
"Notification",
")",
"error",
"{",
"engineConn",
",",
"err",
":=",
"net",
".",
"DialTimeout",
"(",
"\"unix\"",
",",
"s",
".",
"config",
".",
"EngineSocket",
",",
"engineTimeout",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"engineConn",
".",
"SetDeadline",
"(",
"time",
".",
"Now",
"(",
")",
".",
"Add",
"(",
"engineTimeout",
")",
")",
"\n",
"engine",
":=",
"rpc",
".",
"NewClient",
"(",
"engineConn",
")",
"\n",
"defer",
"engine",
".",
"Close",
"(",
")",
"\n",
"var",
"reply",
"int",
"\n",
"ctx",
":=",
"ipc",
".",
"NewTrustedContext",
"(",
"seesaw",
".",
"SCHealthcheck",
")",
"\n",
"return",
"engine",
".",
"Call",
"(",
"\"SeesawEngine.HealthState\"",
",",
"&",
"HealthState",
"{",
"ctx",
",",
"batch",
"}",
",",
"&",
"reply",
")",
"\n",
"}"
] | // sendBatch sends a batch of notifications to the Seesaw Engine. | [
"sendBatch",
"sends",
"a",
"batch",
"of",
"notifications",
"to",
"the",
"Seesaw",
"Engine",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L604-L616 | train |
google/seesaw | ecu/stats.go | newECUStats | func newECUStats(ecu *ECU) *ecuStats {
return &ecuStats{
ecu: ecu,
stats: &stats{
lastUpdate: time.Unix(0, 0),
lastSuccess: time.Unix(0, 0),
},
}
} | go | func newECUStats(ecu *ECU) *ecuStats {
return &ecuStats{
ecu: ecu,
stats: &stats{
lastUpdate: time.Unix(0, 0),
lastSuccess: time.Unix(0, 0),
},
}
} | [
"func",
"newECUStats",
"(",
"ecu",
"*",
"ECU",
")",
"*",
"ecuStats",
"{",
"return",
"&",
"ecuStats",
"{",
"ecu",
":",
"ecu",
",",
"stats",
":",
"&",
"stats",
"{",
"lastUpdate",
":",
"time",
".",
"Unix",
"(",
"0",
",",
"0",
")",
",",
"lastSuccess",
":",
"time",
".",
"Unix",
"(",
"0",
",",
"0",
")",
",",
"}",
",",
"}",
"\n",
"}"
] | // newECUStats returns an initialised ecuStats struct. | [
"newECUStats",
"returns",
"an",
"initialised",
"ecuStats",
"struct",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ecu/stats.go#L63-L71 | train |
google/seesaw | ecu/stats.go | notify | func (e *ecuStats) notify(p publisher) {
e.publishers = append(e.publishers, p)
} | go | func (e *ecuStats) notify(p publisher) {
e.publishers = append(e.publishers, p)
} | [
"func",
"(",
"e",
"*",
"ecuStats",
")",
"notify",
"(",
"p",
"publisher",
")",
"{",
"e",
".",
"publishers",
"=",
"append",
"(",
"e",
".",
"publishers",
",",
"p",
")",
"\n",
"}"
] | // notify registers a publisher for update notifications. | [
"notify",
"registers",
"a",
"publisher",
"for",
"update",
"notifications",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ecu/stats.go#L74-L76 | train |
google/seesaw | ecu/stats.go | run | func (e *ecuStats) run() {
ticker := time.NewTicker(e.ecu.cfg.UpdateInterval)
for {
e.stats.lock.Lock()
e.stats.lastUpdate = time.Now()
e.stats.lock.Unlock()
log.Info("Updating ECU statistics from Seesaw Engine...")
if err := e.update(); err != nil {
log.Warning(err)
} else {
e.stats.lock.Lock()
e.stats.lastSuccess = time.Now()
e.stats.lock.Unlock()
}
for _, p := range e.publishers {
p.update(e.stats)
}
<-ticker.C
}
} | go | func (e *ecuStats) run() {
ticker := time.NewTicker(e.ecu.cfg.UpdateInterval)
for {
e.stats.lock.Lock()
e.stats.lastUpdate = time.Now()
e.stats.lock.Unlock()
log.Info("Updating ECU statistics from Seesaw Engine...")
if err := e.update(); err != nil {
log.Warning(err)
} else {
e.stats.lock.Lock()
e.stats.lastSuccess = time.Now()
e.stats.lock.Unlock()
}
for _, p := range e.publishers {
p.update(e.stats)
}
<-ticker.C
}
} | [
"func",
"(",
"e",
"*",
"ecuStats",
")",
"run",
"(",
")",
"{",
"ticker",
":=",
"time",
".",
"NewTicker",
"(",
"e",
".",
"ecu",
".",
"cfg",
".",
"UpdateInterval",
")",
"\n",
"for",
"{",
"e",
".",
"stats",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"e",
".",
"stats",
".",
"lastUpdate",
"=",
"time",
".",
"Now",
"(",
")",
"\n",
"e",
".",
"stats",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"log",
".",
"Info",
"(",
"\"Updating ECU statistics from Seesaw Engine...\"",
")",
"\n",
"if",
"err",
":=",
"e",
".",
"update",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warning",
"(",
"err",
")",
"\n",
"}",
"else",
"{",
"e",
".",
"stats",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"e",
".",
"stats",
".",
"lastSuccess",
"=",
"time",
".",
"Now",
"(",
")",
"\n",
"e",
".",
"stats",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"e",
".",
"publishers",
"{",
"p",
".",
"update",
"(",
"e",
".",
"stats",
")",
"\n",
"}",
"\n",
"<-",
"ticker",
".",
"C",
"\n",
"}",
"\n",
"}"
] | // run attempts to update the cached statistics from the Seesaw Engine at
// regular intervals. | [
"run",
"attempts",
"to",
"update",
"the",
"cached",
"statistics",
"from",
"the",
"Seesaw",
"Engine",
"at",
"regular",
"intervals",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ecu/stats.go#L80-L100 | train |
google/seesaw | ecu/stats.go | update | func (e *ecuStats) update() error {
// TODO(jsing): Make this untrusted.
ctx := ipc.NewTrustedContext(seesaw.SCECU)
seesawConn, err := conn.NewSeesawIPC(ctx)
if err != nil {
return fmt.Errorf("Failed to connect to engine: %v", err)
}
if err := seesawConn.Dial(e.ecu.cfg.EngineSocket); err != nil {
return fmt.Errorf("Failed to connect to engine: %v", err)
}
defer seesawConn.Close()
clusterStatus, err := seesawConn.ClusterStatus()
if err != nil {
return fmt.Errorf("Failed to get cluster status: %v", err)
}
e.stats.lock.Lock()
e.stats.ClusterStatus = *clusterStatus
e.stats.lock.Unlock()
configStatus, err := seesawConn.ConfigStatus()
if err != nil {
return fmt.Errorf("Failed to get config status: %v", err)
}
e.stats.lock.Lock()
e.stats.ConfigStatus = *configStatus
e.stats.lock.Unlock()
ha, err := seesawConn.HAStatus()
if err != nil {
return fmt.Errorf("Failed to get HA status: %v", err)
}
e.stats.lock.Lock()
e.stats.HAStatus = *ha
e.stats.lock.Unlock()
neighbors, err := seesawConn.BGPNeighbors()
if err != nil {
return fmt.Errorf("Failed to get BGP neighbors: %v", err)
}
e.stats.lock.Lock()
e.stats.neighbors = neighbors
e.stats.lock.Unlock()
vlans, err := seesawConn.VLANs()
if err != nil {
return fmt.Errorf("Failed to get VLANs: %v", err)
}
e.stats.lock.Lock()
e.stats.vlans = vlans.VLANs
e.stats.lock.Unlock()
vservers, err := seesawConn.Vservers()
if err != nil {
return fmt.Errorf("Failed to get vservers: %v", err)
}
e.stats.lock.Lock()
e.stats.vservers = vservers
e.stats.lock.Unlock()
return nil
} | go | func (e *ecuStats) update() error {
// TODO(jsing): Make this untrusted.
ctx := ipc.NewTrustedContext(seesaw.SCECU)
seesawConn, err := conn.NewSeesawIPC(ctx)
if err != nil {
return fmt.Errorf("Failed to connect to engine: %v", err)
}
if err := seesawConn.Dial(e.ecu.cfg.EngineSocket); err != nil {
return fmt.Errorf("Failed to connect to engine: %v", err)
}
defer seesawConn.Close()
clusterStatus, err := seesawConn.ClusterStatus()
if err != nil {
return fmt.Errorf("Failed to get cluster status: %v", err)
}
e.stats.lock.Lock()
e.stats.ClusterStatus = *clusterStatus
e.stats.lock.Unlock()
configStatus, err := seesawConn.ConfigStatus()
if err != nil {
return fmt.Errorf("Failed to get config status: %v", err)
}
e.stats.lock.Lock()
e.stats.ConfigStatus = *configStatus
e.stats.lock.Unlock()
ha, err := seesawConn.HAStatus()
if err != nil {
return fmt.Errorf("Failed to get HA status: %v", err)
}
e.stats.lock.Lock()
e.stats.HAStatus = *ha
e.stats.lock.Unlock()
neighbors, err := seesawConn.BGPNeighbors()
if err != nil {
return fmt.Errorf("Failed to get BGP neighbors: %v", err)
}
e.stats.lock.Lock()
e.stats.neighbors = neighbors
e.stats.lock.Unlock()
vlans, err := seesawConn.VLANs()
if err != nil {
return fmt.Errorf("Failed to get VLANs: %v", err)
}
e.stats.lock.Lock()
e.stats.vlans = vlans.VLANs
e.stats.lock.Unlock()
vservers, err := seesawConn.Vservers()
if err != nil {
return fmt.Errorf("Failed to get vservers: %v", err)
}
e.stats.lock.Lock()
e.stats.vservers = vservers
e.stats.lock.Unlock()
return nil
} | [
"func",
"(",
"e",
"*",
"ecuStats",
")",
"update",
"(",
")",
"error",
"{",
"ctx",
":=",
"ipc",
".",
"NewTrustedContext",
"(",
"seesaw",
".",
"SCECU",
")",
"\n",
"seesawConn",
",",
"err",
":=",
"conn",
".",
"NewSeesawIPC",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"Failed to connect to engine: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"seesawConn",
".",
"Dial",
"(",
"e",
".",
"ecu",
".",
"cfg",
".",
"EngineSocket",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"Failed to connect to engine: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"seesawConn",
".",
"Close",
"(",
")",
"\n",
"clusterStatus",
",",
"err",
":=",
"seesawConn",
".",
"ClusterStatus",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"Failed to get cluster status: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"e",
".",
"stats",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"e",
".",
"stats",
".",
"ClusterStatus",
"=",
"*",
"clusterStatus",
"\n",
"e",
".",
"stats",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"configStatus",
",",
"err",
":=",
"seesawConn",
".",
"ConfigStatus",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"Failed to get config status: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"e",
".",
"stats",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"e",
".",
"stats",
".",
"ConfigStatus",
"=",
"*",
"configStatus",
"\n",
"e",
".",
"stats",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"ha",
",",
"err",
":=",
"seesawConn",
".",
"HAStatus",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"Failed to get HA status: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"e",
".",
"stats",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"e",
".",
"stats",
".",
"HAStatus",
"=",
"*",
"ha",
"\n",
"e",
".",
"stats",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"neighbors",
",",
"err",
":=",
"seesawConn",
".",
"BGPNeighbors",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"Failed to get BGP neighbors: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"e",
".",
"stats",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"e",
".",
"stats",
".",
"neighbors",
"=",
"neighbors",
"\n",
"e",
".",
"stats",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"vlans",
",",
"err",
":=",
"seesawConn",
".",
"VLANs",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"Failed to get VLANs: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"e",
".",
"stats",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"e",
".",
"stats",
".",
"vlans",
"=",
"vlans",
".",
"VLANs",
"\n",
"e",
".",
"stats",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"vservers",
",",
"err",
":=",
"seesawConn",
".",
"Vservers",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"Failed to get vservers: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"e",
".",
"stats",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"e",
".",
"stats",
".",
"vservers",
"=",
"vservers",
"\n",
"e",
".",
"stats",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // update attempts to update the cached statistics from the Seesaw Engine. | [
"update",
"attempts",
"to",
"update",
"the",
"cached",
"statistics",
"from",
"the",
"Seesaw",
"Engine",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ecu/stats.go#L103-L164 | train |
google/seesaw | engine/healthcheck.go | newHealthcheckManager | func newHealthcheckManager(e *Engine) *healthcheckManager {
return &healthcheckManager{
engine: e,
marks: make(map[seesaw.IP]uint32),
markAlloc: newMarkAllocator(dsrMarkBase, dsrMarkSize),
ncc: ncclient.NewNCC(e.config.NCCSocket),
next: healthcheck.Id((uint64(os.Getpid()) & 0xFFFF) << 48),
vserverChecks: make(map[string]map[checkKey]*check),
quit: make(chan bool),
stopped: make(chan bool),
vcc: make(chan vserverChecks, 100),
}
} | go | func newHealthcheckManager(e *Engine) *healthcheckManager {
return &healthcheckManager{
engine: e,
marks: make(map[seesaw.IP]uint32),
markAlloc: newMarkAllocator(dsrMarkBase, dsrMarkSize),
ncc: ncclient.NewNCC(e.config.NCCSocket),
next: healthcheck.Id((uint64(os.Getpid()) & 0xFFFF) << 48),
vserverChecks: make(map[string]map[checkKey]*check),
quit: make(chan bool),
stopped: make(chan bool),
vcc: make(chan vserverChecks, 100),
}
} | [
"func",
"newHealthcheckManager",
"(",
"e",
"*",
"Engine",
")",
"*",
"healthcheckManager",
"{",
"return",
"&",
"healthcheckManager",
"{",
"engine",
":",
"e",
",",
"marks",
":",
"make",
"(",
"map",
"[",
"seesaw",
".",
"IP",
"]",
"uint32",
")",
",",
"markAlloc",
":",
"newMarkAllocator",
"(",
"dsrMarkBase",
",",
"dsrMarkSize",
")",
",",
"ncc",
":",
"ncclient",
".",
"NewNCC",
"(",
"e",
".",
"config",
".",
"NCCSocket",
")",
",",
"next",
":",
"healthcheck",
".",
"Id",
"(",
"(",
"uint64",
"(",
"os",
".",
"Getpid",
"(",
")",
")",
"&",
"0xFFFF",
")",
"<<",
"48",
")",
",",
"vserverChecks",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"map",
"[",
"checkKey",
"]",
"*",
"check",
")",
",",
"quit",
":",
"make",
"(",
"chan",
"bool",
")",
",",
"stopped",
":",
"make",
"(",
"chan",
"bool",
")",
",",
"vcc",
":",
"make",
"(",
"chan",
"vserverChecks",
",",
"100",
")",
",",
"}",
"\n",
"}"
] | // newHealthcheckManager creates a new healthcheckManager. | [
"newHealthcheckManager",
"creates",
"a",
"new",
"healthcheckManager",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/healthcheck.go#L68-L80 | train |
google/seesaw | engine/healthcheck.go | configs | func (h *healthcheckManager) configs() map[healthcheck.Id]*healthcheck.Config {
h.lock.RLock()
defer h.lock.RUnlock()
if !h.enabled {
return nil
}
return h.cfgs
} | go | func (h *healthcheckManager) configs() map[healthcheck.Id]*healthcheck.Config {
h.lock.RLock()
defer h.lock.RUnlock()
if !h.enabled {
return nil
}
return h.cfgs
} | [
"func",
"(",
"h",
"*",
"healthcheckManager",
")",
"configs",
"(",
")",
"map",
"[",
"healthcheck",
".",
"Id",
"]",
"*",
"healthcheck",
".",
"Config",
"{",
"h",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"h",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"!",
"h",
".",
"enabled",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"h",
".",
"cfgs",
"\n",
"}"
] | // configs returns the healthcheck Configs for a Seesaw Engine. The returned
// map should only be read, not mutated. If the healthcheckManager is disabled,
// then nil is returned. | [
"configs",
"returns",
"the",
"healthcheck",
"Configs",
"for",
"a",
"Seesaw",
"Engine",
".",
"The",
"returned",
"map",
"should",
"only",
"be",
"read",
"not",
"mutated",
".",
"If",
"the",
"healthcheckManager",
"is",
"disabled",
"then",
"nil",
"is",
"returned",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/healthcheck.go#L85-L92 | train |
google/seesaw | engine/healthcheck.go | update | func (h *healthcheckManager) update(vserverName string, checks map[checkKey]*check) {
if checks == nil {
delete(h.vserverChecks, vserverName)
} else {
h.vserverChecks[vserverName] = checks
}
h.buildMaps()
} | go | func (h *healthcheckManager) update(vserverName string, checks map[checkKey]*check) {
if checks == nil {
delete(h.vserverChecks, vserverName)
} else {
h.vserverChecks[vserverName] = checks
}
h.buildMaps()
} | [
"func",
"(",
"h",
"*",
"healthcheckManager",
")",
"update",
"(",
"vserverName",
"string",
",",
"checks",
"map",
"[",
"checkKey",
"]",
"*",
"check",
")",
"{",
"if",
"checks",
"==",
"nil",
"{",
"delete",
"(",
"h",
".",
"vserverChecks",
",",
"vserverName",
")",
"\n",
"}",
"else",
"{",
"h",
".",
"vserverChecks",
"[",
"vserverName",
"]",
"=",
"checks",
"\n",
"}",
"\n",
"h",
".",
"buildMaps",
"(",
")",
"\n",
"}"
] | // update updates the healthchecks for a vserver. | [
"update",
"updates",
"the",
"healthchecks",
"for",
"a",
"vserver",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/healthcheck.go#L95-L102 | train |
google/seesaw | engine/healthcheck.go | enable | func (h *healthcheckManager) enable() {
h.lock.Lock()
defer h.lock.Unlock()
h.enabled = true
} | go | func (h *healthcheckManager) enable() {
h.lock.Lock()
defer h.lock.Unlock()
h.enabled = true
} | [
"func",
"(",
"h",
"*",
"healthcheckManager",
")",
"enable",
"(",
")",
"{",
"h",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"h",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"h",
".",
"enabled",
"=",
"true",
"\n",
"}"
] | // enable enables the healthcheck manager for the Seesaw Engine. | [
"enable",
"enables",
"the",
"healthcheck",
"manager",
"for",
"the",
"Seesaw",
"Engine",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/healthcheck.go#L105-L109 | train |
google/seesaw | engine/healthcheck.go | disable | func (h *healthcheckManager) disable() {
h.lock.Lock()
defer h.lock.Unlock()
h.enabled = false
} | go | func (h *healthcheckManager) disable() {
h.lock.Lock()
defer h.lock.Unlock()
h.enabled = false
} | [
"func",
"(",
"h",
"*",
"healthcheckManager",
")",
"disable",
"(",
")",
"{",
"h",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"h",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"h",
".",
"enabled",
"=",
"false",
"\n",
"}"
] | // disable disables the healthcheck manager for the Seesaw Engine. | [
"disable",
"disables",
"the",
"healthcheck",
"manager",
"for",
"the",
"Seesaw",
"Engine",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/healthcheck.go#L112-L116 | train |
google/seesaw | engine/healthcheck.go | buildMaps | func (h *healthcheckManager) buildMaps() {
allChecks := make(map[checkKey]*check)
for _, vchecks := range h.vserverChecks {
for k, c := range vchecks {
if allChecks[k] == nil {
allChecks[k] = c
} else {
log.Warningf("Duplicate key: %v", k)
}
}
}
h.lock.RLock()
ids := h.ids
cfgs := h.cfgs
checks := h.checks
h.lock.RUnlock()
newIDs := make(map[checkKey]healthcheck.Id)
newCfgs := make(map[healthcheck.Id]*healthcheck.Config)
newChecks := make(map[healthcheck.Id]*check)
for key, c := range allChecks {
id, ok := ids[key]
if !ok {
id = h.next
h.next++
}
// Create a new healthcheck configuration if one did not
// previously exist, or if the check configuration changed.
cfg, ok := cfgs[id]
if !ok || *checks[id].healthcheck != *c.healthcheck {
newCfg, err := h.newConfig(id, key, c.healthcheck)
if err != nil {
log.Error(err)
continue
}
cfg = newCfg
}
newIDs[key] = id
newCfgs[id] = cfg
newChecks[id] = c
}
h.lock.Lock()
h.ids = newIDs
h.cfgs = newCfgs
h.checks = newChecks
h.lock.Unlock()
h.pruneMarks()
} | go | func (h *healthcheckManager) buildMaps() {
allChecks := make(map[checkKey]*check)
for _, vchecks := range h.vserverChecks {
for k, c := range vchecks {
if allChecks[k] == nil {
allChecks[k] = c
} else {
log.Warningf("Duplicate key: %v", k)
}
}
}
h.lock.RLock()
ids := h.ids
cfgs := h.cfgs
checks := h.checks
h.lock.RUnlock()
newIDs := make(map[checkKey]healthcheck.Id)
newCfgs := make(map[healthcheck.Id]*healthcheck.Config)
newChecks := make(map[healthcheck.Id]*check)
for key, c := range allChecks {
id, ok := ids[key]
if !ok {
id = h.next
h.next++
}
// Create a new healthcheck configuration if one did not
// previously exist, or if the check configuration changed.
cfg, ok := cfgs[id]
if !ok || *checks[id].healthcheck != *c.healthcheck {
newCfg, err := h.newConfig(id, key, c.healthcheck)
if err != nil {
log.Error(err)
continue
}
cfg = newCfg
}
newIDs[key] = id
newCfgs[id] = cfg
newChecks[id] = c
}
h.lock.Lock()
h.ids = newIDs
h.cfgs = newCfgs
h.checks = newChecks
h.lock.Unlock()
h.pruneMarks()
} | [
"func",
"(",
"h",
"*",
"healthcheckManager",
")",
"buildMaps",
"(",
")",
"{",
"allChecks",
":=",
"make",
"(",
"map",
"[",
"checkKey",
"]",
"*",
"check",
")",
"\n",
"for",
"_",
",",
"vchecks",
":=",
"range",
"h",
".",
"vserverChecks",
"{",
"for",
"k",
",",
"c",
":=",
"range",
"vchecks",
"{",
"if",
"allChecks",
"[",
"k",
"]",
"==",
"nil",
"{",
"allChecks",
"[",
"k",
"]",
"=",
"c",
"\n",
"}",
"else",
"{",
"log",
".",
"Warningf",
"(",
"\"Duplicate key: %v\"",
",",
"k",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"h",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"ids",
":=",
"h",
".",
"ids",
"\n",
"cfgs",
":=",
"h",
".",
"cfgs",
"\n",
"checks",
":=",
"h",
".",
"checks",
"\n",
"h",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n",
"newIDs",
":=",
"make",
"(",
"map",
"[",
"checkKey",
"]",
"healthcheck",
".",
"Id",
")",
"\n",
"newCfgs",
":=",
"make",
"(",
"map",
"[",
"healthcheck",
".",
"Id",
"]",
"*",
"healthcheck",
".",
"Config",
")",
"\n",
"newChecks",
":=",
"make",
"(",
"map",
"[",
"healthcheck",
".",
"Id",
"]",
"*",
"check",
")",
"\n",
"for",
"key",
",",
"c",
":=",
"range",
"allChecks",
"{",
"id",
",",
"ok",
":=",
"ids",
"[",
"key",
"]",
"\n",
"if",
"!",
"ok",
"{",
"id",
"=",
"h",
".",
"next",
"\n",
"h",
".",
"next",
"++",
"\n",
"}",
"\n",
"cfg",
",",
"ok",
":=",
"cfgs",
"[",
"id",
"]",
"\n",
"if",
"!",
"ok",
"||",
"*",
"checks",
"[",
"id",
"]",
".",
"healthcheck",
"!=",
"*",
"c",
".",
"healthcheck",
"{",
"newCfg",
",",
"err",
":=",
"h",
".",
"newConfig",
"(",
"id",
",",
"key",
",",
"c",
".",
"healthcheck",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"cfg",
"=",
"newCfg",
"\n",
"}",
"\n",
"newIDs",
"[",
"key",
"]",
"=",
"id",
"\n",
"newCfgs",
"[",
"id",
"]",
"=",
"cfg",
"\n",
"newChecks",
"[",
"id",
"]",
"=",
"c",
"\n",
"}",
"\n",
"h",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"h",
".",
"ids",
"=",
"newIDs",
"\n",
"h",
".",
"cfgs",
"=",
"newCfgs",
"\n",
"h",
".",
"checks",
"=",
"newChecks",
"\n",
"h",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"h",
".",
"pruneMarks",
"(",
")",
"\n",
"}"
] | // buildMaps builds the cfgs, checks, and ids maps based on the vserverChecks. | [
"buildMaps",
"builds",
"the",
"cfgs",
"checks",
"and",
"ids",
"maps",
"based",
"on",
"the",
"vserverChecks",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/healthcheck.go#L125-L177 | train |
google/seesaw | engine/healthcheck.go | healthState | func (h *healthcheckManager) healthState(n *healthcheck.Notification) error {
log.V(1).Infof("Received healthcheck notification: %v", n)
h.lock.RLock()
enabled := h.enabled
h.lock.RUnlock()
if !enabled {
log.Warningf("Healthcheck manager is disabled; ignoring healthcheck notification %v", n)
return nil
}
h.engine.syncServer.notify(&SyncNote{Type: SNTHealthcheck, Healthcheck: n})
return h.queueHealthState(n)
} | go | func (h *healthcheckManager) healthState(n *healthcheck.Notification) error {
log.V(1).Infof("Received healthcheck notification: %v", n)
h.lock.RLock()
enabled := h.enabled
h.lock.RUnlock()
if !enabled {
log.Warningf("Healthcheck manager is disabled; ignoring healthcheck notification %v", n)
return nil
}
h.engine.syncServer.notify(&SyncNote{Type: SNTHealthcheck, Healthcheck: n})
return h.queueHealthState(n)
} | [
"func",
"(",
"h",
"*",
"healthcheckManager",
")",
"healthState",
"(",
"n",
"*",
"healthcheck",
".",
"Notification",
")",
"error",
"{",
"log",
".",
"V",
"(",
"1",
")",
".",
"Infof",
"(",
"\"Received healthcheck notification: %v\"",
",",
"n",
")",
"\n",
"h",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"enabled",
":=",
"h",
".",
"enabled",
"\n",
"h",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"!",
"enabled",
"{",
"log",
".",
"Warningf",
"(",
"\"Healthcheck manager is disabled; ignoring healthcheck notification %v\"",
",",
"n",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"h",
".",
"engine",
".",
"syncServer",
".",
"notify",
"(",
"&",
"SyncNote",
"{",
"Type",
":",
"SNTHealthcheck",
",",
"Healthcheck",
":",
"n",
"}",
")",
"\n",
"return",
"h",
".",
"queueHealthState",
"(",
"n",
")",
"\n",
"}"
] | // healthState handles Notifications from the healthcheck component. | [
"healthState",
"handles",
"Notifications",
"from",
"the",
"healthcheck",
"component",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/healthcheck.go#L180-L195 | train |
google/seesaw | engine/healthcheck.go | queueHealthState | func (h *healthcheckManager) queueHealthState(n *healthcheck.Notification) error {
h.lock.RLock()
cfg := h.cfgs[n.Id]
check := h.checks[n.Id]
h.lock.RUnlock()
if cfg == nil || check == nil {
log.Warningf("Unknown healthcheck ID %v", n.Id)
return nil
}
note := &checkNotification{
key: check.key,
description: cfg.Checker.String(),
status: n.Status,
}
check.vserver.queueCheckNotification(note)
return nil
} | go | func (h *healthcheckManager) queueHealthState(n *healthcheck.Notification) error {
h.lock.RLock()
cfg := h.cfgs[n.Id]
check := h.checks[n.Id]
h.lock.RUnlock()
if cfg == nil || check == nil {
log.Warningf("Unknown healthcheck ID %v", n.Id)
return nil
}
note := &checkNotification{
key: check.key,
description: cfg.Checker.String(),
status: n.Status,
}
check.vserver.queueCheckNotification(note)
return nil
} | [
"func",
"(",
"h",
"*",
"healthcheckManager",
")",
"queueHealthState",
"(",
"n",
"*",
"healthcheck",
".",
"Notification",
")",
"error",
"{",
"h",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"cfg",
":=",
"h",
".",
"cfgs",
"[",
"n",
".",
"Id",
"]",
"\n",
"check",
":=",
"h",
".",
"checks",
"[",
"n",
".",
"Id",
"]",
"\n",
"h",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"cfg",
"==",
"nil",
"||",
"check",
"==",
"nil",
"{",
"log",
".",
"Warningf",
"(",
"\"Unknown healthcheck ID %v\"",
",",
"n",
".",
"Id",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"note",
":=",
"&",
"checkNotification",
"{",
"key",
":",
"check",
".",
"key",
",",
"description",
":",
"cfg",
".",
"Checker",
".",
"String",
"(",
")",
",",
"status",
":",
"n",
".",
"Status",
",",
"}",
"\n",
"check",
".",
"vserver",
".",
"queueCheckNotification",
"(",
"note",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // queueHealthState queues a health state Notification for processing by a
// vserver. | [
"queueHealthState",
"queues",
"a",
"health",
"state",
"Notification",
"for",
"processing",
"by",
"a",
"vserver",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/healthcheck.go#L199-L218 | train |
google/seesaw | engine/healthcheck.go | run | func (h *healthcheckManager) run() {
for {
select {
case <-h.quit:
h.unmarkAllBackends()
h.stopped <- true
case vc := <-h.vcc:
h.update(vc.vserverName, vc.checks)
}
}
} | go | func (h *healthcheckManager) run() {
for {
select {
case <-h.quit:
h.unmarkAllBackends()
h.stopped <- true
case vc := <-h.vcc:
h.update(vc.vserverName, vc.checks)
}
}
} | [
"func",
"(",
"h",
"*",
"healthcheckManager",
")",
"run",
"(",
")",
"{",
"for",
"{",
"select",
"{",
"case",
"<-",
"h",
".",
"quit",
":",
"h",
".",
"unmarkAllBackends",
"(",
")",
"\n",
"h",
".",
"stopped",
"<-",
"true",
"\n",
"case",
"vc",
":=",
"<-",
"h",
".",
"vcc",
":",
"h",
".",
"update",
"(",
"vc",
".",
"vserverName",
",",
"vc",
".",
"checks",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // run runs the healthcheck manager and processes incoming vserver checks. | [
"run",
"runs",
"the",
"healthcheck",
"manager",
"and",
"processes",
"incoming",
"vserver",
"checks",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/healthcheck.go#L345-L355 | train |
google/seesaw | engine/healthcheck.go | expire | func (h *healthcheckManager) expire() {
h.lock.RLock()
ids := h.ids
h.lock.RUnlock()
status := healthcheck.Status{State: healthcheck.StateUnknown}
for _, id := range ids {
h.queueHealthState(&healthcheck.Notification{id, status})
}
} | go | func (h *healthcheckManager) expire() {
h.lock.RLock()
ids := h.ids
h.lock.RUnlock()
status := healthcheck.Status{State: healthcheck.StateUnknown}
for _, id := range ids {
h.queueHealthState(&healthcheck.Notification{id, status})
}
} | [
"func",
"(",
"h",
"*",
"healthcheckManager",
")",
"expire",
"(",
")",
"{",
"h",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"ids",
":=",
"h",
".",
"ids",
"\n",
"h",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n",
"status",
":=",
"healthcheck",
".",
"Status",
"{",
"State",
":",
"healthcheck",
".",
"StateUnknown",
"}",
"\n",
"for",
"_",
",",
"id",
":=",
"range",
"ids",
"{",
"h",
".",
"queueHealthState",
"(",
"&",
"healthcheck",
".",
"Notification",
"{",
"id",
",",
"status",
"}",
")",
"\n",
"}",
"\n",
"}"
] | // expire invalidates the state of all configured healthchecks. | [
"expire",
"invalidates",
"the",
"state",
"of",
"all",
"configured",
"healthchecks",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/healthcheck.go#L358-L367 | train |
google/seesaw | engine/healthcheck.go | markBackend | func (h *healthcheckManager) markBackend(backend seesaw.IP) uint32 {
mark, ok := h.marks[backend]
if ok {
return mark
}
mark, err := h.markAlloc.get()
if err != nil {
log.Fatalf("Failed to get mark: %v", err)
}
h.marks[backend] = mark
ip := net.IPv6zero
if backend.AF() == seesaw.IPv4 {
ip = net.IPv4zero
}
ipvsSvc := &ipvs.Service{
Address: ip,
Protocol: ipvs.IPProto(0),
Port: 0,
Scheduler: "rr",
FirewallMark: mark,
Destinations: []*ipvs.Destination{
{
Address: backend.IP(),
Port: 0,
Weight: 1,
Flags: ipvs.DFForwardRoute,
},
},
}
if err := h.ncc.Dial(); err != nil {
log.Fatalf("Failed to connect to NCC: %v", err)
}
defer h.ncc.Close()
log.Infof("Adding DSR IPVS service for %s (mark %d)", backend, mark)
if err := h.ncc.IPVSAddService(ipvsSvc); err != nil {
log.Fatalf("Failed to add IPVS service for DSR: %v", err)
}
return mark
} | go | func (h *healthcheckManager) markBackend(backend seesaw.IP) uint32 {
mark, ok := h.marks[backend]
if ok {
return mark
}
mark, err := h.markAlloc.get()
if err != nil {
log.Fatalf("Failed to get mark: %v", err)
}
h.marks[backend] = mark
ip := net.IPv6zero
if backend.AF() == seesaw.IPv4 {
ip = net.IPv4zero
}
ipvsSvc := &ipvs.Service{
Address: ip,
Protocol: ipvs.IPProto(0),
Port: 0,
Scheduler: "rr",
FirewallMark: mark,
Destinations: []*ipvs.Destination{
{
Address: backend.IP(),
Port: 0,
Weight: 1,
Flags: ipvs.DFForwardRoute,
},
},
}
if err := h.ncc.Dial(); err != nil {
log.Fatalf("Failed to connect to NCC: %v", err)
}
defer h.ncc.Close()
log.Infof("Adding DSR IPVS service for %s (mark %d)", backend, mark)
if err := h.ncc.IPVSAddService(ipvsSvc); err != nil {
log.Fatalf("Failed to add IPVS service for DSR: %v", err)
}
return mark
} | [
"func",
"(",
"h",
"*",
"healthcheckManager",
")",
"markBackend",
"(",
"backend",
"seesaw",
".",
"IP",
")",
"uint32",
"{",
"mark",
",",
"ok",
":=",
"h",
".",
"marks",
"[",
"backend",
"]",
"\n",
"if",
"ok",
"{",
"return",
"mark",
"\n",
"}",
"\n",
"mark",
",",
"err",
":=",
"h",
".",
"markAlloc",
".",
"get",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"Failed to get mark: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"h",
".",
"marks",
"[",
"backend",
"]",
"=",
"mark",
"\n",
"ip",
":=",
"net",
".",
"IPv6zero",
"\n",
"if",
"backend",
".",
"AF",
"(",
")",
"==",
"seesaw",
".",
"IPv4",
"{",
"ip",
"=",
"net",
".",
"IPv4zero",
"\n",
"}",
"\n",
"ipvsSvc",
":=",
"&",
"ipvs",
".",
"Service",
"{",
"Address",
":",
"ip",
",",
"Protocol",
":",
"ipvs",
".",
"IPProto",
"(",
"0",
")",
",",
"Port",
":",
"0",
",",
"Scheduler",
":",
"\"rr\"",
",",
"FirewallMark",
":",
"mark",
",",
"Destinations",
":",
"[",
"]",
"*",
"ipvs",
".",
"Destination",
"{",
"{",
"Address",
":",
"backend",
".",
"IP",
"(",
")",
",",
"Port",
":",
"0",
",",
"Weight",
":",
"1",
",",
"Flags",
":",
"ipvs",
".",
"DFForwardRoute",
",",
"}",
",",
"}",
",",
"}",
"\n",
"if",
"err",
":=",
"h",
".",
"ncc",
".",
"Dial",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"Failed to connect to NCC: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"h",
".",
"ncc",
".",
"Close",
"(",
")",
"\n",
"log",
".",
"Infof",
"(",
"\"Adding DSR IPVS service for %s (mark %d)\"",
",",
"backend",
",",
"mark",
")",
"\n",
"if",
"err",
":=",
"h",
".",
"ncc",
".",
"IPVSAddService",
"(",
"ipvsSvc",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"Failed to add IPVS service for DSR: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"mark",
"\n",
"}"
] | // markBackend returns a mark for the specified backend and sets up the IPVS
// service entry if it does not exist. | [
"markBackend",
"returns",
"a",
"mark",
"for",
"the",
"specified",
"backend",
"and",
"sets",
"up",
"the",
"IPVS",
"service",
"entry",
"if",
"it",
"does",
"not",
"exist",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/healthcheck.go#L371-L415 | train |
google/seesaw | engine/healthcheck.go | pruneMarks | func (h *healthcheckManager) pruneMarks() {
h.lock.RLock()
checks := h.checks
h.lock.RUnlock()
backends := make(map[seesaw.IP]bool)
for _, check := range checks {
if check.key.healthcheckMode != seesaw.HCModeDSR {
continue
}
backends[check.key.backendIP] = true
}
for ip := range h.marks {
if _, ok := backends[ip]; !ok {
h.unmarkBackend(ip)
}
}
} | go | func (h *healthcheckManager) pruneMarks() {
h.lock.RLock()
checks := h.checks
h.lock.RUnlock()
backends := make(map[seesaw.IP]bool)
for _, check := range checks {
if check.key.healthcheckMode != seesaw.HCModeDSR {
continue
}
backends[check.key.backendIP] = true
}
for ip := range h.marks {
if _, ok := backends[ip]; !ok {
h.unmarkBackend(ip)
}
}
} | [
"func",
"(",
"h",
"*",
"healthcheckManager",
")",
"pruneMarks",
"(",
")",
"{",
"h",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"checks",
":=",
"h",
".",
"checks",
"\n",
"h",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n",
"backends",
":=",
"make",
"(",
"map",
"[",
"seesaw",
".",
"IP",
"]",
"bool",
")",
"\n",
"for",
"_",
",",
"check",
":=",
"range",
"checks",
"{",
"if",
"check",
".",
"key",
".",
"healthcheckMode",
"!=",
"seesaw",
".",
"HCModeDSR",
"{",
"continue",
"\n",
"}",
"\n",
"backends",
"[",
"check",
".",
"key",
".",
"backendIP",
"]",
"=",
"true",
"\n",
"}",
"\n",
"for",
"ip",
":=",
"range",
"h",
".",
"marks",
"{",
"if",
"_",
",",
"ok",
":=",
"backends",
"[",
"ip",
"]",
";",
"!",
"ok",
"{",
"h",
".",
"unmarkBackend",
"(",
"ip",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // pruneMarks unmarks backends that no longer have DSR healthchecks configured. | [
"pruneMarks",
"unmarks",
"backends",
"that",
"no",
"longer",
"have",
"DSR",
"healthchecks",
"configured",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/healthcheck.go#L461-L479 | train |
google/seesaw | engine/config/notifier.go | NewNotifier | func NewNotifier(ec *EngineConfig) (*Notifier, error) {
outgoing := make(chan Notification, 1)
n := &Notifier{
C: outgoing,
outgoing: outgoing,
reload: make(chan bool, 1),
shutdown: make(chan bool, 1),
engineCfg: ec,
source: SourcePeer,
}
note, err := n.bootstrap()
if err != nil {
return nil, err
}
// If the on disk configuration is different, update it.
if note.Source != SourceDisk {
dNote, _ := n.pullConfig(SourceDisk)
if dNote == nil || !dNote.Cluster.Equal(note.Cluster) {
if err := saveConfig(note.protobuf, n.engineCfg.ClusterFile, true); err != nil {
log.Warningf("Failed to save config to %s: %v", n.engineCfg.ClusterFile, err)
}
}
}
n.last = note
n.outgoing <- *note
go n.run()
return n, nil
} | go | func NewNotifier(ec *EngineConfig) (*Notifier, error) {
outgoing := make(chan Notification, 1)
n := &Notifier{
C: outgoing,
outgoing: outgoing,
reload: make(chan bool, 1),
shutdown: make(chan bool, 1),
engineCfg: ec,
source: SourcePeer,
}
note, err := n.bootstrap()
if err != nil {
return nil, err
}
// If the on disk configuration is different, update it.
if note.Source != SourceDisk {
dNote, _ := n.pullConfig(SourceDisk)
if dNote == nil || !dNote.Cluster.Equal(note.Cluster) {
if err := saveConfig(note.protobuf, n.engineCfg.ClusterFile, true); err != nil {
log.Warningf("Failed to save config to %s: %v", n.engineCfg.ClusterFile, err)
}
}
}
n.last = note
n.outgoing <- *note
go n.run()
return n, nil
} | [
"func",
"NewNotifier",
"(",
"ec",
"*",
"EngineConfig",
")",
"(",
"*",
"Notifier",
",",
"error",
")",
"{",
"outgoing",
":=",
"make",
"(",
"chan",
"Notification",
",",
"1",
")",
"\n",
"n",
":=",
"&",
"Notifier",
"{",
"C",
":",
"outgoing",
",",
"outgoing",
":",
"outgoing",
",",
"reload",
":",
"make",
"(",
"chan",
"bool",
",",
"1",
")",
",",
"shutdown",
":",
"make",
"(",
"chan",
"bool",
",",
"1",
")",
",",
"engineCfg",
":",
"ec",
",",
"source",
":",
"SourcePeer",
",",
"}",
"\n",
"note",
",",
"err",
":=",
"n",
".",
"bootstrap",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"note",
".",
"Source",
"!=",
"SourceDisk",
"{",
"dNote",
",",
"_",
":=",
"n",
".",
"pullConfig",
"(",
"SourceDisk",
")",
"\n",
"if",
"dNote",
"==",
"nil",
"||",
"!",
"dNote",
".",
"Cluster",
".",
"Equal",
"(",
"note",
".",
"Cluster",
")",
"{",
"if",
"err",
":=",
"saveConfig",
"(",
"note",
".",
"protobuf",
",",
"n",
".",
"engineCfg",
".",
"ClusterFile",
",",
"true",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warningf",
"(",
"\"Failed to save config to %s: %v\"",
",",
"n",
".",
"engineCfg",
".",
"ClusterFile",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"n",
".",
"last",
"=",
"note",
"\n",
"n",
".",
"outgoing",
"<-",
"*",
"note",
"\n",
"go",
"n",
".",
"run",
"(",
")",
"\n",
"return",
"n",
",",
"nil",
"\n",
"}"
] | // NewNotifier creates a new Notifier. | [
"NewNotifier",
"creates",
"a",
"new",
"Notifier",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/config/notifier.go#L57-L88 | train |
google/seesaw | engine/config/notifier.go | Source | func (n *Notifier) Source() Source {
n.lock.RLock()
defer n.lock.RUnlock()
return n.source
} | go | func (n *Notifier) Source() Source {
n.lock.RLock()
defer n.lock.RUnlock()
return n.source
} | [
"func",
"(",
"n",
"*",
"Notifier",
")",
"Source",
"(",
")",
"Source",
"{",
"n",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"n",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"n",
".",
"source",
"\n",
"}"
] | // Source returns the current configuration source. | [
"Source",
"returns",
"the",
"current",
"configuration",
"source",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/config/notifier.go#L91-L95 | train |
google/seesaw | engine/config/notifier.go | SetSource | func (n *Notifier) SetSource(source Source) {
n.lock.Lock()
n.source = source
n.lock.Unlock()
if err := n.Reload(); err != nil {
log.Warningf("Reload failed after setting source: %v", err)
}
} | go | func (n *Notifier) SetSource(source Source) {
n.lock.Lock()
n.source = source
n.lock.Unlock()
if err := n.Reload(); err != nil {
log.Warningf("Reload failed after setting source: %v", err)
}
} | [
"func",
"(",
"n",
"*",
"Notifier",
")",
"SetSource",
"(",
"source",
"Source",
")",
"{",
"n",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"n",
".",
"source",
"=",
"source",
"\n",
"n",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
":=",
"n",
".",
"Reload",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warningf",
"(",
"\"Reload failed after setting source: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}"
] | // SetSource sets the configuration Source for a Notifier. | [
"SetSource",
"sets",
"the",
"configuration",
"Source",
"for",
"a",
"Notifier",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/config/notifier.go#L98-L105 | train |
google/seesaw | engine/config/notifier.go | Reload | func (n *Notifier) Reload() error {
select {
case n.reload <- true:
default:
return errors.New("reload request already queued")
}
return nil
} | go | func (n *Notifier) Reload() error {
select {
case n.reload <- true:
default:
return errors.New("reload request already queued")
}
return nil
} | [
"func",
"(",
"n",
"*",
"Notifier",
")",
"Reload",
"(",
")",
"error",
"{",
"select",
"{",
"case",
"n",
".",
"reload",
"<-",
"true",
":",
"default",
":",
"return",
"errors",
".",
"New",
"(",
"\"reload request already queued\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Reload requests an immediate reload from the configuration source. | [
"Reload",
"requests",
"an",
"immediate",
"reload",
"from",
"the",
"configuration",
"source",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/config/notifier.go#L108-L115 | train |
google/seesaw | engine/config/notifier.go | configCheck | func (n *Notifier) configCheck() {
log.Infof("Checking for config changes...")
s := n.Source()
last := n.last
note, err := n.pullConfig(s)
if err != nil && s == SourcePeer {
log.Errorf("Failed to pull configuration from peer: %v", err)
n.peerFailures++
if n.peerFailures < n.engineCfg.MaxPeerConfigSyncErrors {
return
}
log.Infof("Sync from peer failed %v times, falling back to config server",
n.engineCfg.MaxPeerConfigSyncErrors)
s = SourceServer
note, err = n.pullConfig(s)
}
n.peerFailures = 0
if err != nil {
log.Errorf("Failed to pull configuration: %v", err)
return
}
if s != SourceDisk && s != SourcePeer {
oldMeta := last.protobuf.Metadata
newMeta := note.protobuf.Metadata
if oldMeta != nil && newMeta != nil && oldMeta.GetLastUpdated() > newMeta.GetLastUpdated() {
log.Infof("Ignoring out-of-date config from %v", note.SourceDetail)
return
}
}
if note.Cluster.Equal(last.Cluster) {
log.Infof("No config changes found")
return
}
// If there's only metadata differences, note it so we can skip some processing later.
oldCluster := *n.last.Cluster
oldCluster.Status = seesaw.ConfigStatus{}
newCluster := *note.Cluster
newCluster.Status = seesaw.ConfigStatus{}
if newCluster.Equal(&oldCluster) {
note.MetadataOnly = true
}
log.Infof("Sending config update notification")
n.last = note
n.outgoing <- *note
log.Infof("Sent config update notification")
if s != SourceDisk {
if err := saveConfig(note.protobuf, n.engineCfg.ClusterFile, !note.MetadataOnly); err != nil {
log.Warningf("Failed to save config to %s: %v", n.engineCfg.ClusterFile, err)
}
}
} | go | func (n *Notifier) configCheck() {
log.Infof("Checking for config changes...")
s := n.Source()
last := n.last
note, err := n.pullConfig(s)
if err != nil && s == SourcePeer {
log.Errorf("Failed to pull configuration from peer: %v", err)
n.peerFailures++
if n.peerFailures < n.engineCfg.MaxPeerConfigSyncErrors {
return
}
log.Infof("Sync from peer failed %v times, falling back to config server",
n.engineCfg.MaxPeerConfigSyncErrors)
s = SourceServer
note, err = n.pullConfig(s)
}
n.peerFailures = 0
if err != nil {
log.Errorf("Failed to pull configuration: %v", err)
return
}
if s != SourceDisk && s != SourcePeer {
oldMeta := last.protobuf.Metadata
newMeta := note.protobuf.Metadata
if oldMeta != nil && newMeta != nil && oldMeta.GetLastUpdated() > newMeta.GetLastUpdated() {
log.Infof("Ignoring out-of-date config from %v", note.SourceDetail)
return
}
}
if note.Cluster.Equal(last.Cluster) {
log.Infof("No config changes found")
return
}
// If there's only metadata differences, note it so we can skip some processing later.
oldCluster := *n.last.Cluster
oldCluster.Status = seesaw.ConfigStatus{}
newCluster := *note.Cluster
newCluster.Status = seesaw.ConfigStatus{}
if newCluster.Equal(&oldCluster) {
note.MetadataOnly = true
}
log.Infof("Sending config update notification")
n.last = note
n.outgoing <- *note
log.Infof("Sent config update notification")
if s != SourceDisk {
if err := saveConfig(note.protobuf, n.engineCfg.ClusterFile, !note.MetadataOnly); err != nil {
log.Warningf("Failed to save config to %s: %v", n.engineCfg.ClusterFile, err)
}
}
} | [
"func",
"(",
"n",
"*",
"Notifier",
")",
"configCheck",
"(",
")",
"{",
"log",
".",
"Infof",
"(",
"\"Checking for config changes...\"",
")",
"\n",
"s",
":=",
"n",
".",
"Source",
"(",
")",
"\n",
"last",
":=",
"n",
".",
"last",
"\n",
"note",
",",
"err",
":=",
"n",
".",
"pullConfig",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"s",
"==",
"SourcePeer",
"{",
"log",
".",
"Errorf",
"(",
"\"Failed to pull configuration from peer: %v\"",
",",
"err",
")",
"\n",
"n",
".",
"peerFailures",
"++",
"\n",
"if",
"n",
".",
"peerFailures",
"<",
"n",
".",
"engineCfg",
".",
"MaxPeerConfigSyncErrors",
"{",
"return",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"Sync from peer failed %v times, falling back to config server\"",
",",
"n",
".",
"engineCfg",
".",
"MaxPeerConfigSyncErrors",
")",
"\n",
"s",
"=",
"SourceServer",
"\n",
"note",
",",
"err",
"=",
"n",
".",
"pullConfig",
"(",
"s",
")",
"\n",
"}",
"\n",
"n",
".",
"peerFailures",
"=",
"0",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"Failed to pull configuration: %v\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"s",
"!=",
"SourceDisk",
"&&",
"s",
"!=",
"SourcePeer",
"{",
"oldMeta",
":=",
"last",
".",
"protobuf",
".",
"Metadata",
"\n",
"newMeta",
":=",
"note",
".",
"protobuf",
".",
"Metadata",
"\n",
"if",
"oldMeta",
"!=",
"nil",
"&&",
"newMeta",
"!=",
"nil",
"&&",
"oldMeta",
".",
"GetLastUpdated",
"(",
")",
">",
"newMeta",
".",
"GetLastUpdated",
"(",
")",
"{",
"log",
".",
"Infof",
"(",
"\"Ignoring out-of-date config from %v\"",
",",
"note",
".",
"SourceDetail",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"note",
".",
"Cluster",
".",
"Equal",
"(",
"last",
".",
"Cluster",
")",
"{",
"log",
".",
"Infof",
"(",
"\"No config changes found\"",
")",
"\n",
"return",
"\n",
"}",
"\n",
"oldCluster",
":=",
"*",
"n",
".",
"last",
".",
"Cluster",
"\n",
"oldCluster",
".",
"Status",
"=",
"seesaw",
".",
"ConfigStatus",
"{",
"}",
"\n",
"newCluster",
":=",
"*",
"note",
".",
"Cluster",
"\n",
"newCluster",
".",
"Status",
"=",
"seesaw",
".",
"ConfigStatus",
"{",
"}",
"\n",
"if",
"newCluster",
".",
"Equal",
"(",
"&",
"oldCluster",
")",
"{",
"note",
".",
"MetadataOnly",
"=",
"true",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"Sending config update notification\"",
")",
"\n",
"n",
".",
"last",
"=",
"note",
"\n",
"n",
".",
"outgoing",
"<-",
"*",
"note",
"\n",
"log",
".",
"Infof",
"(",
"\"Sent config update notification\"",
")",
"\n",
"if",
"s",
"!=",
"SourceDisk",
"{",
"if",
"err",
":=",
"saveConfig",
"(",
"note",
".",
"protobuf",
",",
"n",
".",
"engineCfg",
".",
"ClusterFile",
",",
"!",
"note",
".",
"MetadataOnly",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warningf",
"(",
"\"Failed to save config to %s: %v\"",
",",
"n",
".",
"engineCfg",
".",
"ClusterFile",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // configCheck checks for configuration changes. | [
"configCheck",
"checks",
"for",
"configuration",
"changes",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/config/notifier.go#L138-L194 | train |
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",
"[",
"\"ipc\"",
"]",
";",
"ok",
"{",
"return",
"&",
"Seesaw",
"{",
"newConn",
"(",
"ctx",
")",
"}",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"No Seesaw IPC connection type registered\"",
")",
"\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",
"{",
"opt",
":=",
"cfgOpt",
"(",
"cfg",
",",
"service",
",",
"option",
")",
"\n",
"if",
"opt",
"==",
"\"\"",
"&&",
"required",
"{",
"log",
".",
"Fatalf",
"(",
"\"Service %s has missing %s option\"",
",",
"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",
"(",
"\"Failover\"",
",",
"ctx",
")",
"\n",
"if",
"ctx",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"context is nil\"",
")",
"\n",
"}",
"\n",
"if",
"!",
"ctx",
".",
"IsTrusted",
"(",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"insufficient access\"",
")",
"\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",
"(",
"\"HAConfig\"",
",",
"ctx",
")",
"\n",
"if",
"ctx",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"context is nil\"",
")",
"\n",
"}",
"\n",
"if",
"!",
"ctx",
".",
"IsTrusted",
"(",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"insufficient access\"",
")",
"\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",
"(",
"\"args is nil\"",
")",
"\n",
"}",
"\n",
"ctx",
":=",
"args",
".",
"Ctx",
"\n",
"s",
".",
"trace",
"(",
"\"HAUpdate\"",
",",
"ctx",
")",
"\n",
"if",
"ctx",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"context is nil\"",
")",
"\n",
"}",
"\n",
"if",
"!",
"ctx",
".",
"IsTrusted",
"(",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"insufficient access\"",
")",
"\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",
"(",
"\"args is nil\"",
")",
"\n",
"}",
"\n",
"ctx",
":=",
"args",
".",
"Ctx",
"\n",
"s",
".",
"trace",
"(",
"\"HAState\"",
",",
"ctx",
")",
"\n",
"if",
"ctx",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"context is nil\"",
")",
"\n",
"}",
"\n",
"if",
"!",
"ctx",
".",
"IsTrusted",
"(",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"insufficient access\"",
")",
"\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",
"(",
"\"Healthchecks\"",
",",
"ctx",
")",
"\n",
"if",
"ctx",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"context is nil\"",
")",
"\n",
"}",
"\n",
"if",
"!",
"ctx",
".",
"IsTrusted",
"(",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"insufficient access\"",
")",
"\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",
"(",
"\"args is nil\"",
")",
"\n",
"}",
"\n",
"ctx",
":=",
"args",
".",
"Ctx",
"\n",
"s",
".",
"trace",
"(",
"\"HealthState\"",
",",
"ctx",
")",
"\n",
"if",
"ctx",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"context is nil\"",
")",
"\n",
"}",
"\n",
"if",
"!",
"ctx",
".",
"IsTrusted",
"(",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"insufficient access\"",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"n",
":=",
"range",
"args",
".",
"Notifications",
"{",
"if",
"err",
":=",
"s",
".",
"engine",
".",
"hcManager",
".",
"healthState",
"(",
"n",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\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",
"(",
"\"ClusterStatus\"",
",",
"ctx",
")",
"\n",
"if",
"ctx",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"context is nil\"",
")",
"\n",
"}",
"\n",
"if",
"!",
"ctx",
".",
"IsTrusted",
"(",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"insufficient access\"",
")",
"\n",
"}",
"\n",
"s",
".",
"engine",
".",
"clusterLock",
".",
"RLock",
"(",
")",
"\n",
"cluster",
":=",
"s",
".",
"engine",
".",
"cluster",
"\n",
"s",
".",
"engine",
".",
"clusterLock",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"cluster",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"no cluster configuration loaded\"",
")",
"\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",
"(",
"\"VLANs\"",
",",
"ctx",
")",
"\n",
"if",
"ctx",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"context is nil\"",
")",
"\n",
"}",
"\n",
"if",
"!",
"ctx",
".",
"IsTrusted",
"(",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"insufficient access\"",
")",
"\n",
"}",
"\n",
"if",
"reply",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"VLANs is nil\"",
")",
"\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",
"(",
"\"args is nil\"",
")",
"\n",
"}",
"\n",
"ctx",
":=",
"args",
".",
"Ctx",
"\n",
"s",
".",
"trace",
"(",
"\"OverrideBackend\"",
",",
"ctx",
")",
"\n",
"if",
"ctx",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"context is nil\"",
")",
"\n",
"}",
"\n",
"if",
"!",
"ctx",
".",
"IsTrusted",
"(",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"insufficient access\"",
")",
"\n",
"}",
"\n",
"if",
"args",
".",
"Backend",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"backend is nil\"",
")",
"\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",
"(",
"\"SeesawECU.ClusterStatus\"",
",",
"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",
"(",
"\"SeesawECU.Backends\"",
",",
"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",
"(",
"\"SeesawECU.OverrideBackend\"",
",",
"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",
"(",
"\"ICMP ping to host %v\"",
",",
"hc",
".",
"IP",
")",
"\n",
"seq",
":=",
"hc",
".",
"Seqnum",
"\n",
"hc",
".",
"Seqnum",
"++",
"\n",
"echo",
":=",
"newICMPEchoRequest",
"(",
"hc",
".",
"Proto",
",",
"hc",
".",
"ID",
",",
"seq",
",",
"64",
",",
"[",
"]",
"byte",
"(",
"\"Healthcheck\"",
")",
")",
"\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",
"recvConn",
":=",
"sendConn",
"\n",
"if",
"raddr",
".",
"IsMulticast",
"(",
")",
"{",
"if",
"raddr",
".",
"To4",
"(",
")",
"!=",
"nil",
"{",
"log",
".",
"Infof",
"(",
"\"Using IPv4 multicast\"",
")",
"\n",
"if",
"recvConn",
",",
"err",
"=",
"ListenMulticastIPv4",
"(",
"raddr",
",",
"laddr",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"else",
"{",
"log",
".",
"Infof",
"(",
"\"Using IPv6 multicast\"",
")",
"\n",
"if",
"err",
"=",
"JoinMulticastIPv6",
"(",
"recvConn",
",",
"raddr",
",",
"laddr",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\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",
"(",
"\"ip4:112\"",
",",
"&",
"net",
".",
"IPAddr",
"{",
"IP",
":",
"gaddr",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"f",
",",
"err",
":=",
"c",
".",
"File",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\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",
"err",
"=",
"syscall",
".",
"SetsockoptIPMreq",
"(",
"int",
"(",
"f",
".",
"Fd",
"(",
")",
")",
",",
"syscall",
".",
"IPPROTO_IP",
",",
"syscall",
".",
"IP_ADD_MEMBERSHIP",
",",
"mreq",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\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",
"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",
"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",
"(",
"\"unreachable\"",
")",
"\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",
"(",
"\"Service %q already exists\"",
",",
"name",
")",
"\n",
"}",
"\n",
"svc",
":=",
"newService",
"(",
"name",
",",
"binary",
")",
"\n",
"w",
".",
"services",
"[",
"name",
"]",
"=",
"svc",
"\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",
"(",
"\"Seesaw watchdog starting...\"",
")",
"\n",
"w",
".",
"mapDependencies",
"(",
")",
"\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",
"(",
"\"Failed to find dependency %q for service %q\"",
",",
"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",
"(",
"\"VLANs\"",
",",
"ctx",
")",
"\n",
"authConn",
",",
"err",
":=",
"s",
".",
"ecu",
".",
"authConnect",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"authConn",
".",
"Close",
"(",
")",
"\n",
"vlans",
",",
"err",
":=",
"authConn",
".",
"VLANs",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\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",
"(",
"\"unknown DNS type %q\"",
",",
"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",
"(",
"\"DNS %s %s\"",
",",
"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",
"(",
"\"connection already established\"",
")",
"\n",
"}",
"\n",
"conn",
",",
"err",
":=",
"net",
".",
"Dial",
"(",
"\"unix\"",
",",
"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",
"(",
"\"No connection established\"",
")",
"\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",
"\"(unknown)\"",
"\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",
"(",
"\"%s [pid %d]\"",
",",
"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",
"(",
"\"%s [uid %s]\"",
",",
"u",
".",
"Username",
",",
"u",
".",
"Uid",
")",
"\n",
"}",
"else",
"{",
"ctx",
".",
"User",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"(unknown) [uid %d]\"",
",",
"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",
"\"(nil context)\"",
"\n",
"}",
"\n",
"var",
"s",
"[",
"]",
"string",
"\n",
"if",
"ctx",
".",
"Peer",
".",
"Component",
"!=",
"seesaw",
".",
"SCNone",
"{",
"s",
"=",
"append",
"(",
"s",
",",
"fmt",
".",
"Sprintf",
"(",
"\"peer %s\"",
",",
"ctx",
".",
"Peer",
".",
"Identity",
")",
")",
"\n",
"}",
"\n",
"if",
"ctx",
".",
"Proxy",
".",
"Component",
"!=",
"seesaw",
".",
"SCNone",
"{",
"s",
"=",
"append",
"(",
"s",
",",
"fmt",
".",
"Sprintf",
"(",
"\"via %s\"",
",",
"ctx",
".",
"Proxy",
".",
"Identity",
")",
")",
"\n",
"}",
"\n",
"s",
"=",
"append",
"(",
"s",
",",
"fmt",
".",
"Sprintf",
"(",
"\"as %s (%v auth)\"",
",",
"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",
"(",
"\"Failed to initialise authentication, remote control will likely fail: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"stats",
":=",
"newECUStats",
"(",
"e",
")",
"\n",
"go",
"stats",
".",
"run",
"(",
")",
"\n",
"go",
"e",
".",
"control",
"(",
")",
"\n",
"go",
"e",
".",
"monitoring",
"(",
")",
"\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",
"(",
"\"tcp\"",
",",
"e",
".",
"cfg",
".",
"MonitorAddress",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatal",
"(",
"\"listen error:\"",
",",
"err",
")",
"\n",
"}",
"\n",
"monitorHTTP",
":=",
"&",
"http",
".",
"Server",
"{",
"ReadTimeout",
":",
"30",
"*",
"time",
".",
"Second",
",",
"WriteTimeout",
":",
"30",
"*",
"time",
".",
"Second",
",",
"MaxHeaderBytes",
":",
"1",
"<<",
"20",
",",
"}",
"\n",
"go",
"monitorHTTP",
".",
"Serve",
"(",
"ln",
")",
"\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",
"(",
"\"failed to read CA cert file: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"ok",
":=",
"rootCACerts",
".",
"AppendCertsFromPEM",
"(",
"data",
")",
";",
"!",
"ok",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"failed to load CA certificates\"",
")",
"\n",
"}",
"\n",
"certs",
",",
"err",
":=",
"tls",
".",
"LoadX509KeyPair",
"(",
"e",
".",
"cfg",
".",
"ECUCertFile",
",",
"e",
".",
"cfg",
".",
"ECUKeyFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"failed to load X.509 key pair: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"tlsConfig",
":=",
"&",
"tls",
".",
"Config",
"{",
"Certificates",
":",
"[",
"]",
"tls",
".",
"Certificate",
"{",
"certs",
"}",
",",
"RootCAs",
":",
"rootCACerts",
",",
"ServerName",
":",
"\"seesaw.example.com\"",
",",
"}",
"\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",
"(",
"\"Disabling ECU control server: %v\"",
",",
"err",
")",
"\n",
"<-",
"e",
".",
"shutdownControl",
"\n",
"e",
".",
"shutdownControl",
"<-",
"true",
"\n",
"return",
"\n",
"}",
"\n",
"ln",
",",
"err",
":=",
"net",
".",
"Listen",
"(",
"\"tcp\"",
",",
"e",
".",
"cfg",
".",
"ControlAddress",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatal",
"(",
"\"listen error:\"",
",",
"err",
")",
"\n",
"}",
"\n",
"seesawRPC",
":=",
"rpc",
".",
"NewServer",
"(",
")",
"\n",
"seesawRPC",
".",
"Register",
"(",
"&",
"SeesawECU",
"{",
"e",
"}",
")",
"\n",
"tlsListener",
":=",
"tls",
".",
"NewListener",
"(",
"ln",
",",
"tlsConfig",
")",
"\n",
"go",
"server",
".",
"RPCAccept",
"(",
"tlsListener",
",",
"seesawRPC",
")",
"\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",
"{",
"for",
"_",
",",
"ctl",
":=",
"range",
"seesawSysctls",
"{",
"if",
"_",
",",
"err",
":=",
"sysctl",
"(",
"ctl",
".",
"name",
",",
"ctl",
".",
"value",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"ifaces",
":=",
"[",
"]",
"string",
"{",
"\"all\"",
",",
"\"default\"",
",",
"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",
"{",
"\"net\"",
",",
"strings",
".",
"ToLower",
"(",
"af",
".",
"String",
"(",
")",
")",
",",
"\"conf\"",
",",
"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",
",",
"\"%s\\n\"",
",",
"\\n",
")",
";",
"value",
"err",
"!=",
"nil",
"\n",
"{",
"return",
"\"\"",
",",
"err",
"\n",
"}",
"\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",
"(",
"\"Failed to parse iptables template: %q: %v\"",
",",
"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",
"(",
")",
"{",
"svcRules",
"=",
"append",
"(",
"svcRules",
",",
"newIPTRuleTemplate",
"(",
"iptAppend",
",",
"\"INPUT -p {{.Proto}} -d {{.ServiceVIP}}{{with .Port}} --dport {{.}}{{end}} -j ACCEPT\"",
")",
")",
"\n",
"fwmRule",
":=",
"\"PREROUTING -t mangle -p {{.Proto}} -d {{.ServiceVIP}}\"",
"+",
"\"{{with .Port}} --dport {{.}}{{end}} -j MARK --set-mark {{.FWM}}\"",
"\n",
"fwmRules",
"=",
"append",
"(",
"fwmRules",
",",
"newIPTRuleTemplate",
"(",
"iptAppend",
",",
"fwmRule",
")",
")",
"\n",
"natConntrack",
":=",
"\"PREROUTING -t raw -p {{.Proto}} -d {{.ServiceVIP}}\"",
"+",
"\"{{with .Port}} --dport {{.}}{{end}} -j ACCEPT\"",
"\n",
"natRules",
"=",
"append",
"(",
"natRules",
",",
"newIPTRuleTemplate",
"(",
"iptInsert",
",",
"natConntrack",
")",
")",
"\n",
"natPostrouting",
":=",
"\"POSTROUTING -t nat -m ipvs -p {{.Proto}}{{with .Port}} --vport {{.}}{{end}} \"",
"+",
"\"--vaddr {{.ServiceVIP}} -j SNAT --to-source {{.ClusterVIP}} --random\"",
"\n",
"natRules",
"=",
"append",
"(",
"natRules",
",",
"newIPTRuleTemplate",
"(",
"iptAppend",
",",
"natPostrouting",
")",
")",
"\n",
"vipRulesEnd",
"=",
"append",
"(",
"vipRulesEnd",
",",
"newIPTRuleTemplate",
"(",
"iptAppend",
",",
"\"INPUT -p icmp -d {{.ServiceVIP}} -j ACCEPT\"",
")",
")",
"\n",
"vipRulesEnd",
"=",
"append",
"(",
"vipRulesEnd",
",",
"newIPTRuleTemplate",
"(",
"iptAppend",
",",
"\"INPUT -p ipv6-icmp -d {{.ServiceVIP}} -j ACCEPT\"",
")",
")",
"\n",
"vipRulesEnd",
"=",
"append",
"(",
"vipRulesEnd",
",",
"newIPTRuleTemplate",
"(",
"iptAppend",
",",
"\"INPUT -d {{.ServiceVIP}} -j REJECT\"",
")",
")",
"\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",
"(",
")",
"{",
"if",
"err",
":=",
"iptablesRun",
"(",
"af",
",",
"\"-I INPUT -p tcp --dport 10257 -j ACCEPT\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"iptablesRun",
"(",
"af",
",",
"\"-t raw -A PREROUTING -j NOTRACK\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"iptablesRun",
"(",
"af",
",",
"\"-t raw -A OUTPUT -j NOTRACK\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"iptablesRun",
"(",
"seesaw",
".",
"IPv4",
",",
"fmt",
".",
"Sprintf",
"(",
"\"-t raw -I PREROUTING -d %v/32 -j ACCEPT\"",
",",
"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",
"{",
"\"filter\"",
",",
"\"mangle\"",
",",
"\"raw\"",
"}",
"{",
"if",
"err",
":=",
"iptablesRun",
"(",
"af",
",",
"fmt",
".",
"Sprintf",
"(",
"\"--flush -t %v\"",
",",
"table",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"err",
":=",
"iptablesRun",
"(",
"seesaw",
".",
"IPv4",
",",
"\"--flush -t nat\"",
")",
";",
"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",
"(",
"\"Seesaw Cluster VIP does not have an %s address\"",
",",
"af",
")",
"\n",
"}",
"\n",
"if",
"serviceIP",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"Service VIP does not have an %s address\"",
",",
"af",
")",
"\n",
"}",
"\n",
"executers",
":=",
"make",
"(",
"[",
"]",
"*",
"iptTemplateExecuter",
",",
"0",
")",
"\n",
"vipData",
":=",
"&",
"iptTemplateData",
"{",
"ClusterVIP",
":",
"clusterIP",
",",
"ServiceVIP",
":",
"serviceIP",
",",
"}",
"\n",
"executers",
"=",
"append",
"(",
"executers",
",",
"&",
"iptTemplateExecuter",
"{",
"vipRulesBegin",
",",
"vipData",
"}",
")",
"\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",
"if",
"v",
".",
"FWM",
"[",
"af",
"]",
">",
"0",
"{",
"executers",
"=",
"append",
"(",
"executers",
",",
"newIPTTemplateExecuter",
"(",
"fwmRules",
",",
"svcData",
")",
")",
"\n",
"}",
"\n",
"if",
"ve",
".",
"Mode",
"==",
"seesaw",
".",
"LBModeNAT",
"{",
"executers",
"=",
"append",
"(",
"executers",
",",
"newIPTTemplateExecuter",
"(",
"natRules",
",",
"svcData",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"executers",
"=",
"append",
"(",
"executers",
",",
"&",
"iptTemplateExecuter",
"{",
"vipRulesEnd",
",",
"vipData",
"}",
")",
"\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",
"(",
"\"Initialising IPVS...\"",
")",
"\n",
"if",
"err",
":=",
"ipvs",
".",
"Init",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"IPVS initialisation failed: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"IPVS version %s\"",
",",
"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",
"\"<not configured>\"",
"\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",
"\"<not configured>\"",
"\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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.