repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
google/seesaw | ncc/lb.go | LBInterfaceUp | func (ncc *SeesawNCC) LBInterfaceUp(iface *ncctypes.LBInterface, out *int) error {
// TODO(jsing): Handle IPv6-only, and improve IPv6 route setup.
netIface, err := iface.Interface()
if err != nil {
return err
}
nodeIface, err := net.InterfaceByName(iface.NodeInterface)
if err != nil {
return fmt.Errorf("Faile... | go | func (ncc *SeesawNCC) LBInterfaceUp(iface *ncctypes.LBInterface, out *int) error {
// TODO(jsing): Handle IPv6-only, and improve IPv6 route setup.
netIface, err := iface.Interface()
if err != nil {
return err
}
nodeIface, err := net.InterfaceByName(iface.NodeInterface)
if err != nil {
return fmt.Errorf("Faile... | [
"func",
"(",
"ncc",
"*",
"SeesawNCC",
")",
"LBInterfaceUp",
"(",
"iface",
"*",
"ncctypes",
".",
"LBInterface",
",",
"out",
"*",
"int",
")",
"error",
"{",
"// TODO(jsing): Handle IPv6-only, and improve IPv6 route setup.",
"netIface",
",",
"err",
":=",
"iface",
".",... | // LBInterfaceUp brings the load balancing interface up. | [
"LBInterfaceUp",
"brings",
"the",
"load",
"balancing",
"interface",
"up",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/lb.go#L184-L223 | train |
google/seesaw | ncc/lb.go | LBInterfaceAddVserver | func (ncc *SeesawNCC) LBInterfaceAddVserver(lbVserver *ncctypes.LBInterfaceVserver, out *int) error {
return iptablesAddRules(lbVserver.Vserver, lbVserver.Iface.ClusterVIP, lbVserver.AF)
} | go | func (ncc *SeesawNCC) LBInterfaceAddVserver(lbVserver *ncctypes.LBInterfaceVserver, out *int) error {
return iptablesAddRules(lbVserver.Vserver, lbVserver.Iface.ClusterVIP, lbVserver.AF)
} | [
"func",
"(",
"ncc",
"*",
"SeesawNCC",
")",
"LBInterfaceAddVserver",
"(",
"lbVserver",
"*",
"ncctypes",
".",
"LBInterfaceVserver",
",",
"out",
"*",
"int",
")",
"error",
"{",
"return",
"iptablesAddRules",
"(",
"lbVserver",
".",
"Vserver",
",",
"lbVserver",
".",
... | // LBInterfaceAddVserver adds the specified Vserver to the load balancing interface. | [
"LBInterfaceAddVserver",
"adds",
"the",
"specified",
"Vserver",
"to",
"the",
"load",
"balancing",
"interface",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/lb.go#L226-L228 | train |
google/seesaw | ncc/lb.go | LBInterfaceDeleteVserver | func (ncc *SeesawNCC) LBInterfaceDeleteVserver(lbVserver *ncctypes.LBInterfaceVserver, out *int) error {
return iptablesDeleteRules(lbVserver.Vserver, lbVserver.Iface.ClusterVIP, lbVserver.AF)
} | go | func (ncc *SeesawNCC) LBInterfaceDeleteVserver(lbVserver *ncctypes.LBInterfaceVserver, out *int) error {
return iptablesDeleteRules(lbVserver.Vserver, lbVserver.Iface.ClusterVIP, lbVserver.AF)
} | [
"func",
"(",
"ncc",
"*",
"SeesawNCC",
")",
"LBInterfaceDeleteVserver",
"(",
"lbVserver",
"*",
"ncctypes",
".",
"LBInterfaceVserver",
",",
"out",
"*",
"int",
")",
"error",
"{",
"return",
"iptablesDeleteRules",
"(",
"lbVserver",
".",
"Vserver",
",",
"lbVserver",
... | // LBInterfaceDeleteVserver removes the specified Vserver from the load balancing interface. | [
"LBInterfaceDeleteVserver",
"removes",
"the",
"specified",
"Vserver",
"from",
"the",
"load",
"balancing",
"interface",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/lb.go#L231-L233 | train |
google/seesaw | ncc/lb.go | LBInterfaceAddVIP | func (ncc *SeesawNCC) LBInterfaceAddVIP(vip *ncctypes.LBInterfaceVIP, out *int) error {
switch vip.Type {
case seesaw.UnicastVIP:
netIface, err := vip.Iface.Interface()
if err != nil {
return err
}
iface, network, err := selectInterfaceNetwork(netIface, vip.IP.IP())
if err != nil {
return fmt.Errorf("... | go | func (ncc *SeesawNCC) LBInterfaceAddVIP(vip *ncctypes.LBInterfaceVIP, out *int) error {
switch vip.Type {
case seesaw.UnicastVIP:
netIface, err := vip.Iface.Interface()
if err != nil {
return err
}
iface, network, err := selectInterfaceNetwork(netIface, vip.IP.IP())
if err != nil {
return fmt.Errorf("... | [
"func",
"(",
"ncc",
"*",
"SeesawNCC",
")",
"LBInterfaceAddVIP",
"(",
"vip",
"*",
"ncctypes",
".",
"LBInterfaceVIP",
",",
"out",
"*",
"int",
")",
"error",
"{",
"switch",
"vip",
".",
"Type",
"{",
"case",
"seesaw",
".",
"UnicastVIP",
":",
"netIface",
",",
... | // LBInterfaceAddVIP adds the specified VIP to the load balancing interface. | [
"LBInterfaceAddVIP",
"adds",
"the",
"specified",
"VIP",
"to",
"the",
"load",
"balancing",
"interface",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/lb.go#L236-L270 | train |
google/seesaw | ncc/lb.go | LBInterfaceDeleteVIP | func (ncc *SeesawNCC) LBInterfaceDeleteVIP(vip *ncctypes.LBInterfaceVIP, out *int) error {
switch vip.Type {
case seesaw.UnicastVIP:
netIface, err := vip.Iface.Interface()
if err != nil {
return err
}
iface, network, err := findInterfaceNetwork(netIface, vip.IP.IP())
if err != nil {
return fmt.Errorf(... | go | func (ncc *SeesawNCC) LBInterfaceDeleteVIP(vip *ncctypes.LBInterfaceVIP, out *int) error {
switch vip.Type {
case seesaw.UnicastVIP:
netIface, err := vip.Iface.Interface()
if err != nil {
return err
}
iface, network, err := findInterfaceNetwork(netIface, vip.IP.IP())
if err != nil {
return fmt.Errorf(... | [
"func",
"(",
"ncc",
"*",
"SeesawNCC",
")",
"LBInterfaceDeleteVIP",
"(",
"vip",
"*",
"ncctypes",
".",
"LBInterfaceVIP",
",",
"out",
"*",
"int",
")",
"error",
"{",
"switch",
"vip",
".",
"Type",
"{",
"case",
"seesaw",
".",
"UnicastVIP",
":",
"netIface",
","... | // LBInterfaceDeleteVIP removes the specified VIP from the load balancing
// interface. | [
"LBInterfaceDeleteVIP",
"removes",
"the",
"specified",
"VIP",
"from",
"the",
"load",
"balancing",
"interface",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/lb.go#L274-L326 | train |
google/seesaw | ncc/lb.go | LBInterfaceAddVLAN | func (ncc *SeesawNCC) LBInterfaceAddVLAN(vlan *ncctypes.LBInterfaceVLAN, out *int) error {
netIface, err := vlan.Iface.Interface()
if err != nil {
return err
}
return ifaceAddVLAN(netIface, vlan.VLAN)
} | go | func (ncc *SeesawNCC) LBInterfaceAddVLAN(vlan *ncctypes.LBInterfaceVLAN, out *int) error {
netIface, err := vlan.Iface.Interface()
if err != nil {
return err
}
return ifaceAddVLAN(netIface, vlan.VLAN)
} | [
"func",
"(",
"ncc",
"*",
"SeesawNCC",
")",
"LBInterfaceAddVLAN",
"(",
"vlan",
"*",
"ncctypes",
".",
"LBInterfaceVLAN",
",",
"out",
"*",
"int",
")",
"error",
"{",
"netIface",
",",
"err",
":=",
"vlan",
".",
"Iface",
".",
"Interface",
"(",
")",
"\n",
"if"... | // LBInterfaceAddVLAN creates a VLAN interface on the load balancing interface. | [
"LBInterfaceAddVLAN",
"creates",
"a",
"VLAN",
"interface",
"on",
"the",
"load",
"balancing",
"interface",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/lb.go#L329-L335 | train |
google/seesaw | ncc/lb.go | LBInterfaceDeleteVLAN | func (ncc *SeesawNCC) LBInterfaceDeleteVLAN(vlan *ncctypes.LBInterfaceVLAN, out *int) error {
netIface, err := vlan.Iface.Interface()
if err != nil {
return err
}
return ifaceDelVLAN(netIface, vlan.VLAN)
} | go | func (ncc *SeesawNCC) LBInterfaceDeleteVLAN(vlan *ncctypes.LBInterfaceVLAN, out *int) error {
netIface, err := vlan.Iface.Interface()
if err != nil {
return err
}
return ifaceDelVLAN(netIface, vlan.VLAN)
} | [
"func",
"(",
"ncc",
"*",
"SeesawNCC",
")",
"LBInterfaceDeleteVLAN",
"(",
"vlan",
"*",
"ncctypes",
".",
"LBInterfaceVLAN",
",",
"out",
"*",
"int",
")",
"error",
"{",
"netIface",
",",
"err",
":=",
"vlan",
".",
"Iface",
".",
"Interface",
"(",
")",
"\n",
"... | // LBInterfaceDeleteVLAN deletes a VLAN interface from the load balancing interface. | [
"LBInterfaceDeleteVLAN",
"deletes",
"a",
"VLAN",
"interface",
"from",
"the",
"load",
"balancing",
"interface",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/lb.go#L338-L344 | train |
google/seesaw | ncc/lb.go | vlanInterfaces | func vlanInterfaces(pIface *net.Interface) ([]*net.Interface, error) {
allIfaces, err := net.Interfaces()
if err != nil {
return nil, err
}
ifaces := make([]*net.Interface, 0, len(allIfaces))
prefix := fmt.Sprintf("%s.", pIface.Name)
for i, iface := range allIfaces {
if strings.HasPrefix(iface.Name, prefix) {... | go | func vlanInterfaces(pIface *net.Interface) ([]*net.Interface, error) {
allIfaces, err := net.Interfaces()
if err != nil {
return nil, err
}
ifaces := make([]*net.Interface, 0, len(allIfaces))
prefix := fmt.Sprintf("%s.", pIface.Name)
for i, iface := range allIfaces {
if strings.HasPrefix(iface.Name, prefix) {... | [
"func",
"vlanInterfaces",
"(",
"pIface",
"*",
"net",
".",
"Interface",
")",
"(",
"[",
"]",
"*",
"net",
".",
"Interface",
",",
"error",
")",
"{",
"allIfaces",
",",
"err",
":=",
"net",
".",
"Interfaces",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",... | // vlanInterfaces returns a slice containing the VLAN interfaces associated
// with a physical interface. | [
"vlanInterfaces",
"returns",
"a",
"slice",
"containing",
"the",
"VLAN",
"interfaces",
"associated",
"with",
"a",
"physical",
"interface",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/lb.go#L348-L361 | train |
google/seesaw | ncc/lb.go | findInterfaceNetwork | func findInterfaceNetwork(pIface *net.Interface, ip net.IP) (*net.Interface, *net.IPNet, error) {
ifaces, err := vlanInterfaces(pIface)
ifaces = append(ifaces, pIface)
if err != nil {
return nil, nil, err
}
for _, iface := range ifaces {
if network, _ := findNetwork(iface, ip); network != nil {
return iface... | go | func findInterfaceNetwork(pIface *net.Interface, ip net.IP) (*net.Interface, *net.IPNet, error) {
ifaces, err := vlanInterfaces(pIface)
ifaces = append(ifaces, pIface)
if err != nil {
return nil, nil, err
}
for _, iface := range ifaces {
if network, _ := findNetwork(iface, ip); network != nil {
return iface... | [
"func",
"findInterfaceNetwork",
"(",
"pIface",
"*",
"net",
".",
"Interface",
",",
"ip",
"net",
".",
"IP",
")",
"(",
"*",
"net",
".",
"Interface",
",",
"*",
"net",
".",
"IPNet",
",",
"error",
")",
"{",
"ifaces",
",",
"err",
":=",
"vlanInterfaces",
"("... | // findInterfaceNetwork searches for the given IP address on the given physical
// interface and its associated VLAN interfaces. If the address is not
// configured on any interface, an error is returned. | [
"findInterfaceNetwork",
"searches",
"for",
"the",
"given",
"IP",
"address",
"on",
"the",
"given",
"physical",
"interface",
"and",
"its",
"associated",
"VLAN",
"interfaces",
".",
"If",
"the",
"address",
"is",
"not",
"configured",
"on",
"any",
"interface",
"an",
... | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/lb.go#L366-L378 | train |
google/seesaw | ncc/lb.go | findNetwork | func findNetwork(iface *net.Interface, ip net.IP) (*net.IPNet, error) {
addrs, err := iface.Addrs()
if err != nil {
return nil, fmt.Errorf("Failed to get addresses for interface %q: %v", iface.Name, err)
}
for _, addr := range addrs {
ipStr := addr.String()
ipAddr, ipNet, err := net.ParseCIDR(ipStr)
if err ... | go | func findNetwork(iface *net.Interface, ip net.IP) (*net.IPNet, error) {
addrs, err := iface.Addrs()
if err != nil {
return nil, fmt.Errorf("Failed to get addresses for interface %q: %v", iface.Name, err)
}
for _, addr := range addrs {
ipStr := addr.String()
ipAddr, ipNet, err := net.ParseCIDR(ipStr)
if err ... | [
"func",
"findNetwork",
"(",
"iface",
"*",
"net",
".",
"Interface",
",",
"ip",
"net",
".",
"IP",
")",
"(",
"*",
"net",
".",
"IPNet",
",",
"error",
")",
"{",
"addrs",
",",
"err",
":=",
"iface",
".",
"Addrs",
"(",
")",
"\n",
"if",
"err",
"!=",
"ni... | // findNetwork returns the network for the given IP address on the given
// interface. If the address is not configured on the interface, an error is
// returned. | [
"findNetwork",
"returns",
"the",
"network",
"for",
"the",
"given",
"IP",
"address",
"on",
"the",
"given",
"interface",
".",
"If",
"the",
"address",
"is",
"not",
"configured",
"on",
"the",
"interface",
"an",
"error",
"is",
"returned",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/lb.go#L383-L399 | train |
google/seesaw | watchdog/service.go | newService | func newService(name, binary string) *Service {
return &Service{
name: name,
binary: binary,
args: make([]string, 0),
dependencies: make(map[string]*Service),
dependents: make(map[string]*Service),
done: make(chan bool),
shutdown: make(chan bool, 1),
started: make(chan boo... | go | func newService(name, binary string) *Service {
return &Service{
name: name,
binary: binary,
args: make([]string, 0),
dependencies: make(map[string]*Service),
dependents: make(map[string]*Service),
done: make(chan bool),
shutdown: make(chan bool, 1),
started: make(chan boo... | [
"func",
"newService",
"(",
"name",
",",
"binary",
"string",
")",
"*",
"Service",
"{",
"return",
"&",
"Service",
"{",
"name",
":",
"name",
",",
"binary",
":",
"binary",
",",
"args",
":",
"make",
"(",
"[",
"]",
"string",
",",
"0",
")",
",",
"dependen... | // newService returns an initialised service. | [
"newService",
"returns",
"an",
"initialised",
"service",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/watchdog/service.go#L70-L85 | train |
google/seesaw | watchdog/service.go | AddArgs | func (svc *Service) AddArgs(args string) {
svc.args = strings.Fields(args)
} | go | func (svc *Service) AddArgs(args string) {
svc.args = strings.Fields(args)
} | [
"func",
"(",
"svc",
"*",
"Service",
")",
"AddArgs",
"(",
"args",
"string",
")",
"{",
"svc",
".",
"args",
"=",
"strings",
".",
"Fields",
"(",
"args",
")",
"\n",
"}"
] | // AddArgs adds the given string as arguments. | [
"AddArgs",
"adds",
"the",
"given",
"string",
"as",
"arguments",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/watchdog/service.go#L93-L95 | train |
google/seesaw | watchdog/service.go | SetPriority | func (svc *Service) SetPriority(priority int) error {
if priority < -20 || priority > 19 {
return fmt.Errorf("Invalid priority %d - must be between -20 and 19", priority)
}
svc.priority = priority
return nil
} | go | func (svc *Service) SetPriority(priority int) error {
if priority < -20 || priority > 19 {
return fmt.Errorf("Invalid priority %d - must be between -20 and 19", priority)
}
svc.priority = priority
return nil
} | [
"func",
"(",
"svc",
"*",
"Service",
")",
"SetPriority",
"(",
"priority",
"int",
")",
"error",
"{",
"if",
"priority",
"<",
"-",
"20",
"||",
"priority",
">",
"19",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"priority",
")",
"\n",
"}",... | // SetPriority sets the process priority for a service. | [
"SetPriority",
"sets",
"the",
"process",
"priority",
"for",
"a",
"service",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/watchdog/service.go#L98-L104 | train |
google/seesaw | watchdog/service.go | SetUser | func (svc *Service) SetUser(username string) error {
u, err := user.Lookup(username)
if err != nil {
return err
}
uid, err := strconv.Atoi(u.Uid)
if err != nil {
return err
}
gid, err := strconv.Atoi(u.Gid)
if err != nil {
return err
}
svc.uid = uint32(uid)
svc.gid = uint32(gid)
return nil
} | go | func (svc *Service) SetUser(username string) error {
u, err := user.Lookup(username)
if err != nil {
return err
}
uid, err := strconv.Atoi(u.Uid)
if err != nil {
return err
}
gid, err := strconv.Atoi(u.Gid)
if err != nil {
return err
}
svc.uid = uint32(uid)
svc.gid = uint32(gid)
return nil
} | [
"func",
"(",
"svc",
"*",
"Service",
")",
"SetUser",
"(",
"username",
"string",
")",
"error",
"{",
"u",
",",
"err",
":=",
"user",
".",
"Lookup",
"(",
"username",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"uid",
",... | // SetUser sets the user for a service. | [
"SetUser",
"sets",
"the",
"user",
"for",
"a",
"service",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/watchdog/service.go#L112-L128 | train |
google/seesaw | watchdog/service.go | run | func (svc *Service) run() {
// Wait for dependencies to start.
for _, dep := range svc.dependencies {
log.Infof("Service %s waiting for %s to start", svc.name, dep.name)
select {
case started := <-dep.started:
dep.started <- started
case <-svc.shutdown:
goto done
}
}
for {
if svc.failures > 0 {
... | go | func (svc *Service) run() {
// Wait for dependencies to start.
for _, dep := range svc.dependencies {
log.Infof("Service %s waiting for %s to start", svc.name, dep.name)
select {
case started := <-dep.started:
dep.started <- started
case <-svc.shutdown:
goto done
}
}
for {
if svc.failures > 0 {
... | [
"func",
"(",
"svc",
"*",
"Service",
")",
"run",
"(",
")",
"{",
"// Wait for dependencies to start.",
"for",
"_",
",",
"dep",
":=",
"range",
"svc",
".",
"dependencies",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"svc",
".",
"name",
",",
"dep",
".... | // run runs a service and restarts it upon termination, unless a shutdown
// notification has been received. | [
"run",
"runs",
"a",
"service",
"and",
"restarts",
"it",
"upon",
"termination",
"unless",
"a",
"shutdown",
"notification",
"has",
"been",
"received",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/watchdog/service.go#L132-L173 | train |
google/seesaw | watchdog/service.go | logFile | func (svc *Service) logFile() (*os.File, error) {
name := "seesaw_" + svc.name
t := time.Now()
logName := fmt.Sprintf("%s.log.%04d%02d%02d-%02d%02d%02d", name,
t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second())
f, err := os.Create(path.Join(logDir, logName))
if err != nil {
return nil, err
}
l... | go | func (svc *Service) logFile() (*os.File, error) {
name := "seesaw_" + svc.name
t := time.Now()
logName := fmt.Sprintf("%s.log.%04d%02d%02d-%02d%02d%02d", name,
t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second())
f, err := os.Create(path.Join(logDir, logName))
if err != nil {
return nil, err
}
l... | [
"func",
"(",
"svc",
"*",
"Service",
")",
"logFile",
"(",
")",
"(",
"*",
"os",
".",
"File",
",",
"error",
")",
"{",
"name",
":=",
"\"",
"\"",
"+",
"svc",
".",
"name",
"\n",
"t",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"logName",
":=",
"fmt",... | // logFile creates a log file for this service. | [
"logFile",
"creates",
"a",
"log",
"file",
"for",
"this",
"service",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/watchdog/service.go#L176-L195 | train |
google/seesaw | watchdog/service.go | logSink | func (svc *Service) logSink(f *os.File, r io.ReadCloser) {
_, err := io.Copy(f, r)
if err != nil {
log.Warningf("Service %s - log sink failed: %v", svc.name, err)
}
f.Close()
r.Close()
} | go | func (svc *Service) logSink(f *os.File, r io.ReadCloser) {
_, err := io.Copy(f, r)
if err != nil {
log.Warningf("Service %s - log sink failed: %v", svc.name, err)
}
f.Close()
r.Close()
} | [
"func",
"(",
"svc",
"*",
"Service",
")",
"logSink",
"(",
"f",
"*",
"os",
".",
"File",
",",
"r",
"io",
".",
"ReadCloser",
")",
"{",
"_",
",",
"err",
":=",
"io",
".",
"Copy",
"(",
"f",
",",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log"... | // logSink copies output from the given reader to a log file, before closing
// both the reader and the log file. | [
"logSink",
"copies",
"output",
"from",
"the",
"given",
"reader",
"to",
"a",
"log",
"file",
"before",
"closing",
"both",
"the",
"reader",
"and",
"the",
"log",
"file",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/watchdog/service.go#L199-L206 | train |
google/seesaw | watchdog/service.go | signal | func (svc *Service) signal(sig os.Signal) error {
svc.lock.Lock()
defer svc.lock.Unlock()
if svc.process == nil {
return nil
}
return svc.process.Signal(sig)
} | go | func (svc *Service) signal(sig os.Signal) error {
svc.lock.Lock()
defer svc.lock.Unlock()
if svc.process == nil {
return nil
}
return svc.process.Signal(sig)
} | [
"func",
"(",
"svc",
"*",
"Service",
")",
"signal",
"(",
"sig",
"os",
".",
"Signal",
")",
"error",
"{",
"svc",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"svc",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"if",
"svc",
".",
"process",
"==... | // signal sends a signal to the service. | [
"signal",
"sends",
"a",
"signal",
"to",
"the",
"service",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/watchdog/service.go#L298-L305 | train |
google/seesaw | watchdog/service.go | stop | func (svc *Service) stop() {
// TODO(jsing): Check if it is actually running?
log.Infof("Stopping service %s...", svc.name)
// Wait for dependents to shutdown.
for _, dep := range svc.dependents {
log.Infof("Service %s waiting for %s to stop", svc.name, dep.name)
stopped := <-dep.stopped
dep.stopped <- stopp... | go | func (svc *Service) stop() {
// TODO(jsing): Check if it is actually running?
log.Infof("Stopping service %s...", svc.name)
// Wait for dependents to shutdown.
for _, dep := range svc.dependents {
log.Infof("Service %s waiting for %s to stop", svc.name, dep.name)
stopped := <-dep.stopped
dep.stopped <- stopp... | [
"func",
"(",
"svc",
"*",
"Service",
")",
"stop",
"(",
")",
"{",
"// TODO(jsing): Check if it is actually running?",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"svc",
".",
"name",
")",
"\n\n",
"// Wait for dependents to shutdown.",
"for",
"_",
",",
"dep",
":=",... | // stop stops a running service. | [
"stop",
"stops",
"a",
"running",
"service",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/watchdog/service.go#L308-L329 | train |
google/seesaw | ncc/arp.go | bytes | func (m *arpMessage) bytes() ([]byte, error) {
buf := new(bytes.Buffer)
if err := binary.Write(buf, binary.BigEndian, m.arpHeader); err != nil {
return nil, fmt.Errorf("binary write failed: %v", err)
}
buf.Write(m.senderHardwareAddress)
buf.Write(m.senderProtocolAddress)
buf.Write(m.targetHardwareAddress)
buf... | go | func (m *arpMessage) bytes() ([]byte, error) {
buf := new(bytes.Buffer)
if err := binary.Write(buf, binary.BigEndian, m.arpHeader); err != nil {
return nil, fmt.Errorf("binary write failed: %v", err)
}
buf.Write(m.senderHardwareAddress)
buf.Write(m.senderProtocolAddress)
buf.Write(m.targetHardwareAddress)
buf... | [
"func",
"(",
"m",
"*",
"arpMessage",
")",
"bytes",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"buf",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n\n",
"if",
"err",
":=",
"binary",
".",
"Write",
"(",
"buf",
",",
"binary",
".",... | // bytes returns the wire representation of the ARP message. | [
"bytes",
"returns",
"the",
"wire",
"representation",
"of",
"the",
"ARP",
"message",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/arp.go#L70-L82 | train |
google/seesaw | ncc/arp.go | gratuitousARPReply | func gratuitousARPReply(ip net.IP, mac net.HardwareAddr) (*arpMessage, error) {
if ip.To4() == nil {
return nil, fmt.Errorf("%q is not an IPv4 address", ip)
}
if len(mac) != hwLen {
return nil, fmt.Errorf("%q is not an Ethernet MAC address", mac)
}
m := &arpMessage{
arpHeader{
1, // Ethernet
... | go | func gratuitousARPReply(ip net.IP, mac net.HardwareAddr) (*arpMessage, error) {
if ip.To4() == nil {
return nil, fmt.Errorf("%q is not an IPv4 address", ip)
}
if len(mac) != hwLen {
return nil, fmt.Errorf("%q is not an Ethernet MAC address", mac)
}
m := &arpMessage{
arpHeader{
1, // Ethernet
... | [
"func",
"gratuitousARPReply",
"(",
"ip",
"net",
".",
"IP",
",",
"mac",
"net",
".",
"HardwareAddr",
")",
"(",
"*",
"arpMessage",
",",
"error",
")",
"{",
"if",
"ip",
".",
"To4",
"(",
")",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
... | // gratuitousARPReply returns an ARP message that contains a gratuitous ARP
// reply from the specified sender. | [
"gratuitousARPReply",
"returns",
"an",
"ARP",
"message",
"that",
"contains",
"a",
"gratuitous",
"ARP",
"reply",
"from",
"the",
"specified",
"sender",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/arp.go#L86-L109 | train |
google/seesaw | ncc/arp.go | sendARP | func sendARP(iface *net.Interface, m *arpMessage) error {
fd, err := syscall.Socket(syscall.AF_PACKET, syscall.SOCK_DGRAM, int(htons(syscall.ETH_P_ARP)))
if err != nil {
return fmt.Errorf("failed to get raw socket: %v", err)
}
defer syscall.Close(fd)
if err := syscall.BindToDevice(fd, iface.Name); err != nil {
... | go | func sendARP(iface *net.Interface, m *arpMessage) error {
fd, err := syscall.Socket(syscall.AF_PACKET, syscall.SOCK_DGRAM, int(htons(syscall.ETH_P_ARP)))
if err != nil {
return fmt.Errorf("failed to get raw socket: %v", err)
}
defer syscall.Close(fd)
if err := syscall.BindToDevice(fd, iface.Name); err != nil {
... | [
"func",
"sendARP",
"(",
"iface",
"*",
"net",
".",
"Interface",
",",
"m",
"*",
"arpMessage",
")",
"error",
"{",
"fd",
",",
"err",
":=",
"syscall",
".",
"Socket",
"(",
"syscall",
".",
"AF_PACKET",
",",
"syscall",
".",
"SOCK_DGRAM",
",",
"int",
"(",
"ht... | // sendARP sends the given ARP message via the specified interface. | [
"sendARP",
"sends",
"the",
"given",
"ARP",
"message",
"via",
"the",
"specified",
"interface",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/arp.go#L112-L151 | train |
google/seesaw | ncc/arp.go | ARPSendGratuitous | func (ncc *SeesawNCC) ARPSendGratuitous(arp *ncctypes.ARPGratuitous, out *int) error {
iface, err := net.InterfaceByName(arp.IfaceName)
if err != nil {
return fmt.Errorf("failed to get interface %q: %v", arp.IfaceName, err)
}
log.V(2).Infof("Sending gratuitous ARP for %s (%s) via %s", arp.IP, iface.HardwareAddr, ... | go | func (ncc *SeesawNCC) ARPSendGratuitous(arp *ncctypes.ARPGratuitous, out *int) error {
iface, err := net.InterfaceByName(arp.IfaceName)
if err != nil {
return fmt.Errorf("failed to get interface %q: %v", arp.IfaceName, err)
}
log.V(2).Infof("Sending gratuitous ARP for %s (%s) via %s", arp.IP, iface.HardwareAddr, ... | [
"func",
"(",
"ncc",
"*",
"SeesawNCC",
")",
"ARPSendGratuitous",
"(",
"arp",
"*",
"ncctypes",
".",
"ARPGratuitous",
",",
"out",
"*",
"int",
")",
"error",
"{",
"iface",
",",
"err",
":=",
"net",
".",
"InterfaceByName",
"(",
"arp",
".",
"IfaceName",
")",
"... | // ARPSendGratuitous sends a gratuitous ARP message via the specified interface. | [
"ARPSendGratuitous",
"sends",
"a",
"gratuitous",
"ARP",
"message",
"via",
"the",
"specified",
"interface",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/arp.go#L154-L165 | train |
google/seesaw | healthcheck/radius.go | String | func (rc radiusCode) String() string {
if name, ok := rcNames[rc]; ok {
return name
}
return fmt.Sprintf("(unknown %d)", rc)
} | go | func (rc radiusCode) String() string {
if name, ok := rcNames[rc]; ok {
return name
}
return fmt.Sprintf("(unknown %d)", rc)
} | [
"func",
"(",
"rc",
"radiusCode",
")",
"String",
"(",
")",
"string",
"{",
"if",
"name",
",",
"ok",
":=",
"rcNames",
"[",
"rc",
"]",
";",
"ok",
"{",
"return",
"name",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"rc",
"... | // String returns the string representation of a RADIUS code. | [
"String",
"returns",
"the",
"string",
"representation",
"of",
"a",
"RADIUS",
"code",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/radius.go#L81-L86 | train |
google/seesaw | healthcheck/radius.go | String | func (rat radiusAttributeType) String() string {
if name, ok := ratNames[rat]; ok {
return name
}
return fmt.Sprintf("(unknown %d)", rat)
} | go | func (rat radiusAttributeType) String() string {
if name, ok := ratNames[rat]; ok {
return name
}
return fmt.Sprintf("(unknown %d)", rat)
} | [
"func",
"(",
"rat",
"radiusAttributeType",
")",
"String",
"(",
")",
"string",
"{",
"if",
"name",
",",
"ok",
":=",
"ratNames",
"[",
"rat",
"]",
";",
"ok",
"{",
"return",
"name",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",... | // String returns the string representation of a RADIUS attribute type. | [
"String",
"returns",
"the",
"string",
"representation",
"of",
"a",
"RADIUS",
"attribute",
"type",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/radius.go#L144-L149 | train |
google/seesaw | healthcheck/radius.go | radiusPassword | func radiusPassword(passwd, secret string, authenticator *radiusAuthenticator) []byte {
const blockSize = 16
length := (len(passwd) + 0xf) &^ 0xf
if length > 128 {
length = 128
}
blocks := make([]byte, length)
copy(blocks, []byte(passwd))
for i := 0; i < length; i += blockSize {
hash := md5.New()
hash.Writ... | go | func radiusPassword(passwd, secret string, authenticator *radiusAuthenticator) []byte {
const blockSize = 16
length := (len(passwd) + 0xf) &^ 0xf
if length > 128 {
length = 128
}
blocks := make([]byte, length)
copy(blocks, []byte(passwd))
for i := 0; i < length; i += blockSize {
hash := md5.New()
hash.Writ... | [
"func",
"radiusPassword",
"(",
"passwd",
",",
"secret",
"string",
",",
"authenticator",
"*",
"radiusAuthenticator",
")",
"[",
"]",
"byte",
"{",
"const",
"blockSize",
"=",
"16",
"\n",
"length",
":=",
"(",
"len",
"(",
"passwd",
")",
"+",
"0xf",
")",
"&^",
... | // radiusPassword encodes a password using the algorithm described in RFC2865
// section 5.2. | [
"radiusPassword",
"encodes",
"a",
"password",
"using",
"the",
"algorithm",
"described",
"in",
"RFC2865",
"section",
"5",
".",
"2",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/radius.go#L241-L263 | train |
google/seesaw | healthcheck/radius.go | responseAuthenticator | func responseAuthenticator(rp *radiusPacket, requestAuthenticator *radiusAuthenticator, secret string) (*radiusAuthenticator, error) {
hash := md5.New()
hash.Write([]byte{byte(rp.Code), byte(rp.Identifier)})
if err := binary.Write(hash, binary.BigEndian, rp.Length); err != nil {
return nil, err
}
hash.Write(requ... | go | func responseAuthenticator(rp *radiusPacket, requestAuthenticator *radiusAuthenticator, secret string) (*radiusAuthenticator, error) {
hash := md5.New()
hash.Write([]byte{byte(rp.Code), byte(rp.Identifier)})
if err := binary.Write(hash, binary.BigEndian, rp.Length); err != nil {
return nil, err
}
hash.Write(requ... | [
"func",
"responseAuthenticator",
"(",
"rp",
"*",
"radiusPacket",
",",
"requestAuthenticator",
"*",
"radiusAuthenticator",
",",
"secret",
"string",
")",
"(",
"*",
"radiusAuthenticator",
",",
"error",
")",
"{",
"hash",
":=",
"md5",
".",
"New",
"(",
")",
"\n",
... | // responseAuthenticator calculates the response authenticator for a RADIUS
// response packet, as per RFC2865 section 3. | [
"responseAuthenticator",
"calculates",
"the",
"response",
"authenticator",
"for",
"a",
"RADIUS",
"response",
"packet",
"as",
"per",
"RFC2865",
"section",
"3",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/radius.go#L267-L282 | train |
google/seesaw | healthcheck/radius.go | NewRADIUSChecker | func NewRADIUSChecker(ip net.IP, port int) *RADIUSChecker {
return &RADIUSChecker{
Target: Target{
IP: ip,
Port: port,
Proto: seesaw.IPProtoUDP,
},
Response: "accept",
}
} | go | func NewRADIUSChecker(ip net.IP, port int) *RADIUSChecker {
return &RADIUSChecker{
Target: Target{
IP: ip,
Port: port,
Proto: seesaw.IPProtoUDP,
},
Response: "accept",
}
} | [
"func",
"NewRADIUSChecker",
"(",
"ip",
"net",
".",
"IP",
",",
"port",
"int",
")",
"*",
"RADIUSChecker",
"{",
"return",
"&",
"RADIUSChecker",
"{",
"Target",
":",
"Target",
"{",
"IP",
":",
"ip",
",",
"Port",
":",
"port",
",",
"Proto",
":",
"seesaw",
".... | // NewRADIUSChecker returns an initialised RADIUSChecker. | [
"NewRADIUSChecker",
"returns",
"an",
"initialised",
"RADIUSChecker",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/radius.go#L294-L303 | train |
google/seesaw | engine/config/types.go | NewCluster | func NewCluster(site string) *Cluster {
return &Cluster{
Site: site,
BGPPeers: make(map[string]*seesaw.Host),
Nodes: make(map[string]*seesaw.Node),
VIPSubnets: make(map[string]*net.IPNet),
Vservers: make(map[string]*Vserver),
VLANs: make(map[uint16]*seesaw.VLAN),
Status: seesaw.Config... | go | func NewCluster(site string) *Cluster {
return &Cluster{
Site: site,
BGPPeers: make(map[string]*seesaw.Host),
Nodes: make(map[string]*seesaw.Node),
VIPSubnets: make(map[string]*net.IPNet),
Vservers: make(map[string]*Vserver),
VLANs: make(map[uint16]*seesaw.VLAN),
Status: seesaw.Config... | [
"func",
"NewCluster",
"(",
"site",
"string",
")",
"*",
"Cluster",
"{",
"return",
"&",
"Cluster",
"{",
"Site",
":",
"site",
",",
"BGPPeers",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"seesaw",
".",
"Host",
")",
",",
"Nodes",
":",
"make",
"("... | // NewCluster returns an initialised Cluster structure. | [
"NewCluster",
"returns",
"an",
"initialised",
"Cluster",
"structure",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/config/types.go#L45-L58 | train |
google/seesaw | engine/config/types.go | AddBGPPeer | func (c *Cluster) AddBGPPeer(peer *seesaw.Host) error {
key := peer.Hostname
if _, ok := c.BGPPeers[key]; ok {
return fmt.Errorf("Cluster %q already contains peer %q", c.Site, key)
}
c.BGPPeers[key] = peer
return nil
} | go | func (c *Cluster) AddBGPPeer(peer *seesaw.Host) error {
key := peer.Hostname
if _, ok := c.BGPPeers[key]; ok {
return fmt.Errorf("Cluster %q already contains peer %q", c.Site, key)
}
c.BGPPeers[key] = peer
return nil
} | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"AddBGPPeer",
"(",
"peer",
"*",
"seesaw",
".",
"Host",
")",
"error",
"{",
"key",
":=",
"peer",
".",
"Hostname",
"\n",
"if",
"_",
",",
"ok",
":=",
"c",
".",
"BGPPeers",
"[",
"key",
"]",
";",
"ok",
"{",
"ret... | // AddBGPPeer adds a BGP peer to a Seesaw Cluster. | [
"AddBGPPeer",
"adds",
"a",
"BGP",
"peer",
"to",
"a",
"Seesaw",
"Cluster",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/config/types.go#L61-L68 | train |
google/seesaw | engine/config/types.go | AddNode | func (c *Cluster) AddNode(node *seesaw.Node) error {
key := node.Key()
if _, ok := c.Nodes[key]; ok {
return fmt.Errorf("Cluster %q already contains Node %q", c.Site, key)
}
c.Nodes[key] = node
return nil
} | go | func (c *Cluster) AddNode(node *seesaw.Node) error {
key := node.Key()
if _, ok := c.Nodes[key]; ok {
return fmt.Errorf("Cluster %q already contains Node %q", c.Site, key)
}
c.Nodes[key] = node
return nil
} | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"AddNode",
"(",
"node",
"*",
"seesaw",
".",
"Node",
")",
"error",
"{",
"key",
":=",
"node",
".",
"Key",
"(",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"c",
".",
"Nodes",
"[",
"key",
"]",
";",
"ok",
"{",
"... | // AddNode adds a Seesaw Node to a Seesaw Cluster. | [
"AddNode",
"adds",
"a",
"Seesaw",
"Node",
"to",
"a",
"Seesaw",
"Cluster",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/config/types.go#L71-L78 | train |
google/seesaw | engine/config/types.go | AddVIPSubnet | func (c *Cluster) AddVIPSubnet(subnet *net.IPNet) error {
key := subnet.String()
if _, ok := c.VIPSubnets[key]; ok {
return fmt.Errorf("Cluster %q already contains VIP Subnet %q", c.Site, key)
}
c.VIPSubnets[key] = subnet
return nil
} | go | func (c *Cluster) AddVIPSubnet(subnet *net.IPNet) error {
key := subnet.String()
if _, ok := c.VIPSubnets[key]; ok {
return fmt.Errorf("Cluster %q already contains VIP Subnet %q", c.Site, key)
}
c.VIPSubnets[key] = subnet
return nil
} | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"AddVIPSubnet",
"(",
"subnet",
"*",
"net",
".",
"IPNet",
")",
"error",
"{",
"key",
":=",
"subnet",
".",
"String",
"(",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"c",
".",
"VIPSubnets",
"[",
"key",
"]",
";",
"... | // AddVIPSubnet adds a VIP Subnet to a Seesaw Cluster. | [
"AddVIPSubnet",
"adds",
"a",
"VIP",
"Subnet",
"to",
"a",
"Seesaw",
"Cluster",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/config/types.go#L81-L88 | train |
google/seesaw | engine/config/types.go | AddVserver | func (c *Cluster) AddVserver(vserver *Vserver) error {
key := vserver.Key()
if _, ok := c.Vservers[key]; ok {
return fmt.Errorf("Cluster %q already contains Vserver %q", c.Site, key)
}
c.Vservers[key] = vserver
return nil
} | go | func (c *Cluster) AddVserver(vserver *Vserver) error {
key := vserver.Key()
if _, ok := c.Vservers[key]; ok {
return fmt.Errorf("Cluster %q already contains Vserver %q", c.Site, key)
}
c.Vservers[key] = vserver
return nil
} | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"AddVserver",
"(",
"vserver",
"*",
"Vserver",
")",
"error",
"{",
"key",
":=",
"vserver",
".",
"Key",
"(",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"c",
".",
"Vservers",
"[",
"key",
"]",
";",
"ok",
"{",
"retu... | // AddVserver adds a Vserver to a Seesaw Cluster. | [
"AddVserver",
"adds",
"a",
"Vserver",
"to",
"a",
"Seesaw",
"Cluster",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/config/types.go#L91-L98 | train |
google/seesaw | engine/config/types.go | AddVLAN | func (c *Cluster) AddVLAN(vlan *seesaw.VLAN) error {
key := vlan.Key()
if _, ok := c.VLANs[key]; ok {
return fmt.Errorf("Cluster %q already contains VLAN %q", c.Site, key)
}
c.VLANs[key] = vlan
return nil
} | go | func (c *Cluster) AddVLAN(vlan *seesaw.VLAN) error {
key := vlan.Key()
if _, ok := c.VLANs[key]; ok {
return fmt.Errorf("Cluster %q already contains VLAN %q", c.Site, key)
}
c.VLANs[key] = vlan
return nil
} | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"AddVLAN",
"(",
"vlan",
"*",
"seesaw",
".",
"VLAN",
")",
"error",
"{",
"key",
":=",
"vlan",
".",
"Key",
"(",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"c",
".",
"VLANs",
"[",
"key",
"]",
";",
"ok",
"{",
"... | // AddVLAN adds a VLAN to a Seesaw Cluster. | [
"AddVLAN",
"adds",
"a",
"VLAN",
"to",
"a",
"Seesaw",
"Cluster",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/config/types.go#L101-L108 | train |
google/seesaw | engine/config/types.go | Equal | func (c *Cluster) Equal(other *Cluster) bool {
return reflect.DeepEqual(c, other)
} | go | func (c *Cluster) Equal(other *Cluster) bool {
return reflect.DeepEqual(c, other)
} | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"Equal",
"(",
"other",
"*",
"Cluster",
")",
"bool",
"{",
"return",
"reflect",
".",
"DeepEqual",
"(",
"c",
",",
"other",
")",
"\n",
"}"
] | // Equal reports whether this cluster is equal to the given cluster. | [
"Equal",
"reports",
"whether",
"this",
"cluster",
"is",
"equal",
"to",
"the",
"given",
"cluster",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/config/types.go#L111-L113 | train |
google/seesaw | engine/config/types.go | NewVserver | func NewVserver(name string, host seesaw.Host) *Vserver {
return &Vserver{
Name: name,
Host: host,
Entries: make(map[string]*VserverEntry),
Backends: make(map[string]*seesaw.Backend),
Healthchecks: make(map[string]*Healthcheck),
VIPs: make(map[string]*seesaw.VIP),
Warning... | go | func NewVserver(name string, host seesaw.Host) *Vserver {
return &Vserver{
Name: name,
Host: host,
Entries: make(map[string]*VserverEntry),
Backends: make(map[string]*seesaw.Backend),
Healthchecks: make(map[string]*Healthcheck),
VIPs: make(map[string]*seesaw.VIP),
Warning... | [
"func",
"NewVserver",
"(",
"name",
"string",
",",
"host",
"seesaw",
".",
"Host",
")",
"*",
"Vserver",
"{",
"return",
"&",
"Vserver",
"{",
"Name",
":",
"name",
",",
"Host",
":",
"host",
",",
"Entries",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*... | // NewVserver creates a new, initialised Vserver structure. | [
"NewVserver",
"creates",
"a",
"new",
"initialised",
"Vserver",
"structure",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/config/types.go#L129-L139 | train |
google/seesaw | engine/config/types.go | AddVserverEntry | func (v *Vserver) AddVserverEntry(e *VserverEntry) error {
key := e.Key()
if _, ok := v.Entries[key]; ok {
return fmt.Errorf("Vserver %q already contains VserverEntry %q", v.Name, key)
}
v.Entries[key] = e
return nil
} | go | func (v *Vserver) AddVserverEntry(e *VserverEntry) error {
key := e.Key()
if _, ok := v.Entries[key]; ok {
return fmt.Errorf("Vserver %q already contains VserverEntry %q", v.Name, key)
}
v.Entries[key] = e
return nil
} | [
"func",
"(",
"v",
"*",
"Vserver",
")",
"AddVserverEntry",
"(",
"e",
"*",
"VserverEntry",
")",
"error",
"{",
"key",
":=",
"e",
".",
"Key",
"(",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"v",
".",
"Entries",
"[",
"key",
"]",
";",
"ok",
"{",
"return"... | // AddVserverEntry adds an VserverEntry to a Vserver. | [
"AddVserverEntry",
"adds",
"an",
"VserverEntry",
"to",
"a",
"Vserver",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/config/types.go#L147-L154 | train |
google/seesaw | engine/config/types.go | AddBackend | func (v *Vserver) AddBackend(backend *seesaw.Backend) error {
key := backend.Key()
if _, ok := v.Backends[key]; ok {
return fmt.Errorf("Vserver %q already contains Backend %q", v.Name, key)
}
v.Backends[key] = backend
return nil
} | go | func (v *Vserver) AddBackend(backend *seesaw.Backend) error {
key := backend.Key()
if _, ok := v.Backends[key]; ok {
return fmt.Errorf("Vserver %q already contains Backend %q", v.Name, key)
}
v.Backends[key] = backend
return nil
} | [
"func",
"(",
"v",
"*",
"Vserver",
")",
"AddBackend",
"(",
"backend",
"*",
"seesaw",
".",
"Backend",
")",
"error",
"{",
"key",
":=",
"backend",
".",
"Key",
"(",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"v",
".",
"Backends",
"[",
"key",
"]",
";",
"... | // AddBackend adds a Backend to a Vserver. | [
"AddBackend",
"adds",
"a",
"Backend",
"to",
"a",
"Vserver",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/config/types.go#L157-L164 | train |
google/seesaw | engine/config/types.go | AddHealthcheck | func (v *Vserver) AddHealthcheck(h *Healthcheck) error {
key := h.Key()
if _, ok := v.Healthchecks[key]; ok {
return fmt.Errorf("Vserver %q already contains Healthcheck %q", v.Name, key)
}
v.Healthchecks[key] = h
return nil
} | go | func (v *Vserver) AddHealthcheck(h *Healthcheck) error {
key := h.Key()
if _, ok := v.Healthchecks[key]; ok {
return fmt.Errorf("Vserver %q already contains Healthcheck %q", v.Name, key)
}
v.Healthchecks[key] = h
return nil
} | [
"func",
"(",
"v",
"*",
"Vserver",
")",
"AddHealthcheck",
"(",
"h",
"*",
"Healthcheck",
")",
"error",
"{",
"key",
":=",
"h",
".",
"Key",
"(",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"v",
".",
"Healthchecks",
"[",
"key",
"]",
";",
"ok",
"{",
"retu... | // AddHealthcheck adds a Healthcheck to a Vserver. | [
"AddHealthcheck",
"adds",
"a",
"Healthcheck",
"to",
"a",
"Vserver",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/config/types.go#L167-L174 | train |
google/seesaw | engine/config/types.go | AddVIP | func (v *Vserver) AddVIP(vip *seesaw.VIP) error {
key := vip.String()
if _, ok := v.VIPs[key]; ok {
return fmt.Errorf("Vserver %q already contains VIP %q", v.Name, key)
}
v.VIPs[key] = vip
return nil
} | go | func (v *Vserver) AddVIP(vip *seesaw.VIP) error {
key := vip.String()
if _, ok := v.VIPs[key]; ok {
return fmt.Errorf("Vserver %q already contains VIP %q", v.Name, key)
}
v.VIPs[key] = vip
return nil
} | [
"func",
"(",
"v",
"*",
"Vserver",
")",
"AddVIP",
"(",
"vip",
"*",
"seesaw",
".",
"VIP",
")",
"error",
"{",
"key",
":=",
"vip",
".",
"String",
"(",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"v",
".",
"VIPs",
"[",
"key",
"]",
";",
"ok",
"{",
"re... | // AddVIP adds a VIP to a Vserver. | [
"AddVIP",
"adds",
"a",
"VIP",
"to",
"a",
"Vserver",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/config/types.go#L177-L184 | train |
google/seesaw | engine/config/types.go | NewVserverEntry | func NewVserverEntry(port uint16, proto seesaw.IPProto) *VserverEntry {
return &VserverEntry{
Port: port,
Proto: proto,
Healthchecks: make(map[string]*Healthcheck),
}
} | go | func NewVserverEntry(port uint16, proto seesaw.IPProto) *VserverEntry {
return &VserverEntry{
Port: port,
Proto: proto,
Healthchecks: make(map[string]*Healthcheck),
}
} | [
"func",
"NewVserverEntry",
"(",
"port",
"uint16",
",",
"proto",
"seesaw",
".",
"IPProto",
")",
"*",
"VserverEntry",
"{",
"return",
"&",
"VserverEntry",
"{",
"Port",
":",
"port",
",",
"Proto",
":",
"proto",
",",
"Healthchecks",
":",
"make",
"(",
"map",
"[... | // NewVserverEntry creates a new, initialised VserverEntry structure. | [
"NewVserverEntry",
"creates",
"a",
"new",
"initialised",
"VserverEntry",
"structure",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/config/types.go#L203-L209 | train |
google/seesaw | engine/config/types.go | Key | func (v *VserverEntry) Key() string {
return fmt.Sprintf("%d/%s", v.Port, v.Proto)
} | go | func (v *VserverEntry) Key() string {
return fmt.Sprintf("%d/%s", v.Port, v.Proto)
} | [
"func",
"(",
"v",
"*",
"VserverEntry",
")",
"Key",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"v",
".",
"Port",
",",
"v",
".",
"Proto",
")",
"\n",
"}"
] | // Key returns the unique identifier for a VserverEntry. | [
"Key",
"returns",
"the",
"unique",
"identifier",
"for",
"a",
"VserverEntry",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/config/types.go#L222-L224 | train |
google/seesaw | engine/config/types.go | Snapshot | func (v *VserverEntry) Snapshot() *seesaw.VserverEntry {
return &seesaw.VserverEntry{
Port: v.Port,
Proto: v.Proto,
Scheduler: v.Scheduler,
Mode: v.Mode,
Persistence: v.Persistence,
OnePacket: v.OnePacket,
HighWatermark: v.HighWatermark,
LowWatermark: v.LowWatermark... | go | func (v *VserverEntry) Snapshot() *seesaw.VserverEntry {
return &seesaw.VserverEntry{
Port: v.Port,
Proto: v.Proto,
Scheduler: v.Scheduler,
Mode: v.Mode,
Persistence: v.Persistence,
OnePacket: v.OnePacket,
HighWatermark: v.HighWatermark,
LowWatermark: v.LowWatermark... | [
"func",
"(",
"v",
"*",
"VserverEntry",
")",
"Snapshot",
"(",
")",
"*",
"seesaw",
".",
"VserverEntry",
"{",
"return",
"&",
"seesaw",
".",
"VserverEntry",
"{",
"Port",
":",
"v",
".",
"Port",
",",
"Proto",
":",
"v",
".",
"Proto",
",",
"Scheduler",
":",
... | // Snapshot returns a snapshot for a VserverEntry. | [
"Snapshot",
"returns",
"a",
"snapshot",
"for",
"a",
"VserverEntry",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/config/types.go#L227-L240 | train |
google/seesaw | engine/config/types.go | NewHealthcheck | func NewHealthcheck(m seesaw.HealthcheckMode, t seesaw.HealthcheckType, port uint16) *Healthcheck {
return &Healthcheck{
Mode: m,
Type: t,
Port: port,
}
} | go | func NewHealthcheck(m seesaw.HealthcheckMode, t seesaw.HealthcheckType, port uint16) *Healthcheck {
return &Healthcheck{
Mode: m,
Type: t,
Port: port,
}
} | [
"func",
"NewHealthcheck",
"(",
"m",
"seesaw",
".",
"HealthcheckMode",
",",
"t",
"seesaw",
".",
"HealthcheckType",
",",
"port",
"uint16",
")",
"*",
"Healthcheck",
"{",
"return",
"&",
"Healthcheck",
"{",
"Mode",
":",
"m",
",",
"Type",
":",
"t",
",",
"Port"... | // NewHealthcheck creates a new, initialised Healthcheck structure. | [
"NewHealthcheck",
"creates",
"a",
"new",
"initialised",
"Healthcheck",
"structure",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/config/types.go#L261-L267 | train |
google/seesaw | ncc/bgp.go | quaggaBGP | func quaggaBGP(asn uint32) (*quagga.BGP, error) {
bgp := quagga.NewBGP("", asn)
if err := bgp.Dial(); err != nil {
return nil, err
}
if err := bgp.Enable(); err != nil {
bgp.Close()
return nil, err
}
return bgp, nil
} | go | func quaggaBGP(asn uint32) (*quagga.BGP, error) {
bgp := quagga.NewBGP("", asn)
if err := bgp.Dial(); err != nil {
return nil, err
}
if err := bgp.Enable(); err != nil {
bgp.Close()
return nil, err
}
return bgp, nil
} | [
"func",
"quaggaBGP",
"(",
"asn",
"uint32",
")",
"(",
"*",
"quagga",
".",
"BGP",
",",
"error",
")",
"{",
"bgp",
":=",
"quagga",
".",
"NewBGP",
"(",
"\"",
"\"",
",",
"asn",
")",
"\n",
"if",
"err",
":=",
"bgp",
".",
"Dial",
"(",
")",
";",
"err",
... | // quaggaBGP establishes a connection with the Quagga BGP daemon. | [
"quaggaBGP",
"establishes",
"a",
"connection",
"with",
"the",
"Quagga",
"BGP",
"daemon",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/bgp.go#L36-L46 | train |
google/seesaw | ncc/bgp.go | BGPConfig | func (ncc *SeesawNCC) BGPConfig(unused int, cfg *ncctypes.BGPConfig) error {
bgp, err := quaggaBGP(seesawASN)
if err != nil {
return err
}
defer bgp.Close()
bgpCfg, err := bgp.Configuration()
if err != nil {
return err
}
if cfg != nil {
cfg.Config = bgpCfg
}
return nil
} | go | func (ncc *SeesawNCC) BGPConfig(unused int, cfg *ncctypes.BGPConfig) error {
bgp, err := quaggaBGP(seesawASN)
if err != nil {
return err
}
defer bgp.Close()
bgpCfg, err := bgp.Configuration()
if err != nil {
return err
}
if cfg != nil {
cfg.Config = bgpCfg
}
return nil
} | [
"func",
"(",
"ncc",
"*",
"SeesawNCC",
")",
"BGPConfig",
"(",
"unused",
"int",
",",
"cfg",
"*",
"ncctypes",
".",
"BGPConfig",
")",
"error",
"{",
"bgp",
",",
"err",
":=",
"quaggaBGP",
"(",
"seesawASN",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return"... | // BGPConfig returns the current configuration for the Quagga BGP daemon. | [
"BGPConfig",
"returns",
"the",
"current",
"configuration",
"for",
"the",
"Quagga",
"BGP",
"daemon",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/bgp.go#L49-L63 | train |
google/seesaw | ncc/bgp.go | BGPNeighbors | func (ncc *SeesawNCC) BGPNeighbors(unused int, neighbors *ncctypes.BGPNeighbors) error {
bgp, err := quaggaBGP(seesawASN)
if err != nil {
return err
}
defer bgp.Close()
bgpNeighbors, err := bgp.Neighbors()
if err != nil {
return err
}
if neighbors != nil {
neighbors.Neighbors = bgpNeighbors
}
return nil... | go | func (ncc *SeesawNCC) BGPNeighbors(unused int, neighbors *ncctypes.BGPNeighbors) error {
bgp, err := quaggaBGP(seesawASN)
if err != nil {
return err
}
defer bgp.Close()
bgpNeighbors, err := bgp.Neighbors()
if err != nil {
return err
}
if neighbors != nil {
neighbors.Neighbors = bgpNeighbors
}
return nil... | [
"func",
"(",
"ncc",
"*",
"SeesawNCC",
")",
"BGPNeighbors",
"(",
"unused",
"int",
",",
"neighbors",
"*",
"ncctypes",
".",
"BGPNeighbors",
")",
"error",
"{",
"bgp",
",",
"err",
":=",
"quaggaBGP",
"(",
"seesawASN",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{"... | // BGPNeighbors returns the current BGP neighbors for the Quagga BGP daemon. | [
"BGPNeighbors",
"returns",
"the",
"current",
"BGP",
"neighbors",
"for",
"the",
"Quagga",
"BGP",
"daemon",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/bgp.go#L66-L80 | train |
google/seesaw | ncc/bgp.go | hostMask | func hostMask(ip net.IP) net.IPMask {
var hl int
if ip.To4() != nil {
hl = net.IPv4len * 8
} else {
hl = net.IPv6len * 8
}
return net.CIDRMask(hl, hl)
} | go | func hostMask(ip net.IP) net.IPMask {
var hl int
if ip.To4() != nil {
hl = net.IPv4len * 8
} else {
hl = net.IPv6len * 8
}
return net.CIDRMask(hl, hl)
} | [
"func",
"hostMask",
"(",
"ip",
"net",
".",
"IP",
")",
"net",
".",
"IPMask",
"{",
"var",
"hl",
"int",
"\n",
"if",
"ip",
".",
"To4",
"(",
")",
"!=",
"nil",
"{",
"hl",
"=",
"net",
".",
"IPv4len",
"*",
"8",
"\n",
"}",
"else",
"{",
"hl",
"=",
"n... | // hostMask returns an IP mask that corresponds with a host prefix. | [
"hostMask",
"returns",
"an",
"IP",
"mask",
"that",
"corresponds",
"with",
"a",
"host",
"prefix",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/bgp.go#L83-L91 | train |
google/seesaw | ncc/bgp.go | BGPWithdrawAll | func (ncc *SeesawNCC) BGPWithdrawAll(unused int, reply *int) error {
bgp, err := quaggaBGP(seesawASN)
if err != nil {
return err
}
defer bgp.Close()
bgpCfg, err := bgp.Configuration()
if err != nil {
return err
}
// Find the network statements within the router bgp section.
bgpStr := fmt.Sprintf("router ... | go | func (ncc *SeesawNCC) BGPWithdrawAll(unused int, reply *int) error {
bgp, err := quaggaBGP(seesawASN)
if err != nil {
return err
}
defer bgp.Close()
bgpCfg, err := bgp.Configuration()
if err != nil {
return err
}
// Find the network statements within the router bgp section.
bgpStr := fmt.Sprintf("router ... | [
"func",
"(",
"ncc",
"*",
"SeesawNCC",
")",
"BGPWithdrawAll",
"(",
"unused",
"int",
",",
"reply",
"*",
"int",
")",
"error",
"{",
"bgp",
",",
"err",
":=",
"quaggaBGP",
"(",
"seesawASN",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
... | // BGPWithdrawAll removes all network advertisements from the Quagga BGP daemon. | [
"BGPWithdrawAll",
"removes",
"all",
"network",
"advertisements",
"from",
"the",
"Quagga",
"BGP",
"daemon",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/bgp.go#L94-L134 | train |
google/seesaw | ncc/bgp.go | BGPAdvertiseVIP | func (ncc *SeesawNCC) BGPAdvertiseVIP(vip net.IP, unused *int) error {
bgp, err := quaggaBGP(seesawASN)
if err != nil {
return err
}
defer bgp.Close()
return bgp.Advertise(&net.IPNet{IP: vip, Mask: hostMask(vip)})
} | go | func (ncc *SeesawNCC) BGPAdvertiseVIP(vip net.IP, unused *int) error {
bgp, err := quaggaBGP(seesawASN)
if err != nil {
return err
}
defer bgp.Close()
return bgp.Advertise(&net.IPNet{IP: vip, Mask: hostMask(vip)})
} | [
"func",
"(",
"ncc",
"*",
"SeesawNCC",
")",
"BGPAdvertiseVIP",
"(",
"vip",
"net",
".",
"IP",
",",
"unused",
"*",
"int",
")",
"error",
"{",
"bgp",
",",
"err",
":=",
"quaggaBGP",
"(",
"seesawASN",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"e... | // BGPAdvertiseVIP requests the Quagga BGP daemon to advertise the given VIP. | [
"BGPAdvertiseVIP",
"requests",
"the",
"Quagga",
"BGP",
"daemon",
"to",
"advertise",
"the",
"given",
"VIP",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/bgp.go#L137-L144 | train |
google/seesaw | engine/ha.go | newHAManager | func newHAManager(engine *Engine, timeout time.Duration) *haManager {
now := time.Now()
return &haManager{
engine: engine,
status: seesaw.HAStatus{
LastUpdate: now,
Since: now,
State: seesaw.HAUnknown,
},
timeout: timeout,
stateChan: make(chan seesaw.HAState, 1),
statusChan: make(ch... | go | func newHAManager(engine *Engine, timeout time.Duration) *haManager {
now := time.Now()
return &haManager{
engine: engine,
status: seesaw.HAStatus{
LastUpdate: now,
Since: now,
State: seesaw.HAUnknown,
},
timeout: timeout,
stateChan: make(chan seesaw.HAState, 1),
statusChan: make(ch... | [
"func",
"newHAManager",
"(",
"engine",
"*",
"Engine",
",",
"timeout",
"time",
".",
"Duration",
")",
"*",
"haManager",
"{",
"now",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"return",
"&",
"haManager",
"{",
"engine",
":",
"engine",
",",
"status",
":",
... | // newHAManager creates a new haManager with the given HA state timeout. | [
"newHAManager",
"creates",
"a",
"new",
"haManager",
"with",
"the",
"given",
"HA",
"state",
"timeout",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/ha.go#L45-L58 | train |
google/seesaw | engine/ha.go | state | func (h *haManager) state() seesaw.HAState {
h.statusLock.RLock()
defer h.statusLock.RUnlock()
return h.status.State
} | go | func (h *haManager) state() seesaw.HAState {
h.statusLock.RLock()
defer h.statusLock.RUnlock()
return h.status.State
} | [
"func",
"(",
"h",
"*",
"haManager",
")",
"state",
"(",
")",
"seesaw",
".",
"HAState",
"{",
"h",
".",
"statusLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"h",
".",
"statusLock",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"h",
".",
"status",
".",
"... | // state returns the current HA state known by the engine. | [
"state",
"returns",
"the",
"current",
"HA",
"state",
"known",
"by",
"the",
"engine",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/ha.go#L61-L65 | train |
google/seesaw | engine/ha.go | enable | func (h *haManager) enable() {
if h.state() == seesaw.HADisabled {
h.setState(seesaw.HAUnknown)
}
} | go | func (h *haManager) enable() {
if h.state() == seesaw.HADisabled {
h.setState(seesaw.HAUnknown)
}
} | [
"func",
"(",
"h",
"*",
"haManager",
")",
"enable",
"(",
")",
"{",
"if",
"h",
".",
"state",
"(",
")",
"==",
"seesaw",
".",
"HADisabled",
"{",
"h",
".",
"setState",
"(",
"seesaw",
".",
"HAUnknown",
")",
"\n",
"}",
"\n",
"}"
] | // enable enables HA peering for the node on which the engine is running. | [
"enable",
"enables",
"HA",
"peering",
"for",
"the",
"node",
"on",
"which",
"the",
"engine",
"is",
"running",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/ha.go#L68-L72 | train |
google/seesaw | engine/ha.go | failover | func (h *haManager) failover() bool {
h.failoverLock.Lock()
pending := h.failoverPending
h.failoverPending = false
h.failoverLock.Unlock()
return pending
} | go | func (h *haManager) failover() bool {
h.failoverLock.Lock()
pending := h.failoverPending
h.failoverPending = false
h.failoverLock.Unlock()
return pending
} | [
"func",
"(",
"h",
"*",
"haManager",
")",
"failover",
"(",
")",
"bool",
"{",
"h",
".",
"failoverLock",
".",
"Lock",
"(",
")",
"\n",
"pending",
":=",
"h",
".",
"failoverPending",
"\n",
"h",
".",
"failoverPending",
"=",
"false",
"\n",
"h",
".",
"failove... | // failover returns true if the HA component should relinquish master state. | [
"failover",
"returns",
"true",
"if",
"the",
"HA",
"component",
"should",
"relinquish",
"master",
"state",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/ha.go#L80-L86 | train |
google/seesaw | engine/ha.go | requestFailover | func (h *haManager) requestFailover(peer bool) error {
state := h.state()
if state == seesaw.HAMaster {
h.failoverLock.Lock()
defer h.failoverLock.Unlock()
if h.failoverPending {
return fmt.Errorf("Failover request already pending")
}
h.failoverPending = true
return nil
}
if peer {
return fmt.Erro... | go | func (h *haManager) requestFailover(peer bool) error {
state := h.state()
if state == seesaw.HAMaster {
h.failoverLock.Lock()
defer h.failoverLock.Unlock()
if h.failoverPending {
return fmt.Errorf("Failover request already pending")
}
h.failoverPending = true
return nil
}
if peer {
return fmt.Erro... | [
"func",
"(",
"h",
"*",
"haManager",
")",
"requestFailover",
"(",
"peer",
"bool",
")",
"error",
"{",
"state",
":=",
"h",
".",
"state",
"(",
")",
"\n",
"if",
"state",
"==",
"seesaw",
".",
"HAMaster",
"{",
"h",
".",
"failoverLock",
".",
"Lock",
"(",
"... | // requestFailover requests the node to initiate a failover. | [
"requestFailover",
"requests",
"the",
"node",
"to",
"initiate",
"a",
"failover",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/ha.go#L89-L110 | train |
google/seesaw | engine/ha.go | setState | func (h *haManager) setState(s seesaw.HAState) {
state := h.state()
if state == seesaw.HADisabled && s != seesaw.HAUnknown {
log.Warningf("Invalid HA state transition %v -> %v", state, s)
return
}
if state != s {
log.Infof("HA state transition %v -> %v starting", state, s)
if s == seesaw.HAMaster {
h.e... | go | func (h *haManager) setState(s seesaw.HAState) {
state := h.state()
if state == seesaw.HADisabled && s != seesaw.HAUnknown {
log.Warningf("Invalid HA state transition %v -> %v", state, s)
return
}
if state != s {
log.Infof("HA state transition %v -> %v starting", state, s)
if s == seesaw.HAMaster {
h.e... | [
"func",
"(",
"h",
"*",
"haManager",
")",
"setState",
"(",
"s",
"seesaw",
".",
"HAState",
")",
"{",
"state",
":=",
"h",
".",
"state",
"(",
")",
"\n\n",
"if",
"state",
"==",
"seesaw",
".",
"HADisabled",
"&&",
"s",
"!=",
"seesaw",
".",
"HAUnknown",
"{... | // setState sets the HAState of the engine and dispatches events when the state
// changes. | [
"setState",
"sets",
"the",
"HAState",
"of",
"the",
"engine",
"and",
"dispatches",
"events",
"when",
"the",
"state",
"changes",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/ha.go#L114-L139 | train |
google/seesaw | engine/ha.go | setStatus | func (h *haManager) setStatus(s seesaw.HAStatus) {
h.setState(s.State)
h.statusLock.Lock()
h.status.Since = s.Since
h.status.Sent = s.Sent
h.status.Received = s.Received
h.status.Transitions = s.Transitions
h.statusLock.Unlock()
} | go | func (h *haManager) setStatus(s seesaw.HAStatus) {
h.setState(s.State)
h.statusLock.Lock()
h.status.Since = s.Since
h.status.Sent = s.Sent
h.status.Received = s.Received
h.status.Transitions = s.Transitions
h.statusLock.Unlock()
} | [
"func",
"(",
"h",
"*",
"haManager",
")",
"setStatus",
"(",
"s",
"seesaw",
".",
"HAStatus",
")",
"{",
"h",
".",
"setState",
"(",
"s",
".",
"State",
")",
"\n\n",
"h",
".",
"statusLock",
".",
"Lock",
"(",
")",
"\n",
"h",
".",
"status",
".",
"Since",... | // setStatus updates the engine HAStatus. | [
"setStatus",
"updates",
"the",
"engine",
"HAStatus",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/ha.go#L142-L151 | train |
google/seesaw | engine/ha.go | timer | func (h *haManager) timer() <-chan time.Time {
if s := h.state(); s == seesaw.HADisabled || s == seesaw.HAUnknown {
return make(chan time.Time)
}
// TODO(angusc): Make this clock-jump safe.
h.statusLock.RLock()
deadline := h.status.LastUpdate.Add(h.timeout)
h.statusLock.RUnlock()
return time.After(deadline.Sub... | go | func (h *haManager) timer() <-chan time.Time {
if s := h.state(); s == seesaw.HADisabled || s == seesaw.HAUnknown {
return make(chan time.Time)
}
// TODO(angusc): Make this clock-jump safe.
h.statusLock.RLock()
deadline := h.status.LastUpdate.Add(h.timeout)
h.statusLock.RUnlock()
return time.After(deadline.Sub... | [
"func",
"(",
"h",
"*",
"haManager",
")",
"timer",
"(",
")",
"<-",
"chan",
"time",
".",
"Time",
"{",
"if",
"s",
":=",
"h",
".",
"state",
"(",
")",
";",
"s",
"==",
"seesaw",
".",
"HADisabled",
"||",
"s",
"==",
"seesaw",
".",
"HAUnknown",
"{",
"re... | // timer returns a channel that receives a Time object when the current HA state
// expires. | [
"timer",
"returns",
"a",
"channel",
"that",
"receives",
"a",
"Time",
"object",
"when",
"the",
"current",
"HA",
"state",
"expires",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/ha.go#L155-L164 | train |
google/seesaw | cli/core.go | Execute | func (cli *SeesawCLI) Execute(cmdline string) error {
cmd, subcmds, _, args := FindCommand(cmdline)
if cmd != nil {
return cmd.function(cli, args)
}
if subcmds != nil {
return errors.New("Incomplete command.")
}
return errors.New("Unknown command.")
} | go | func (cli *SeesawCLI) Execute(cmdline string) error {
cmd, subcmds, _, args := FindCommand(cmdline)
if cmd != nil {
return cmd.function(cli, args)
}
if subcmds != nil {
return errors.New("Incomplete command.")
}
return errors.New("Unknown command.")
} | [
"func",
"(",
"cli",
"*",
"SeesawCLI",
")",
"Execute",
"(",
"cmdline",
"string",
")",
"error",
"{",
"cmd",
",",
"subcmds",
",",
"_",
",",
"args",
":=",
"FindCommand",
"(",
"cmdline",
")",
"\n",
"if",
"cmd",
"!=",
"nil",
"{",
"return",
"cmd",
".",
"f... | // Execute executes the given command line. | [
"Execute",
"executes",
"the",
"given",
"command",
"line",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/cli/core.go#L40-L49 | train |
google/seesaw | cli/core.go | FindCommand | func FindCommand(cmdline string) (*Command, *[]Command, []*Command, []string) {
var chain []*Command
var matches []Command
var next *Command
cmds := &commands
// Tokenise string.
cmdstr := strings.Fields(cmdline)
if len(cmdstr) == 0 {
return nil, cmds, chain, nil
}
for idx, subcmd := range cmdstr {
match... | go | func FindCommand(cmdline string) (*Command, *[]Command, []*Command, []string) {
var chain []*Command
var matches []Command
var next *Command
cmds := &commands
// Tokenise string.
cmdstr := strings.Fields(cmdline)
if len(cmdstr) == 0 {
return nil, cmds, chain, nil
}
for idx, subcmd := range cmdstr {
match... | [
"func",
"FindCommand",
"(",
"cmdline",
"string",
")",
"(",
"*",
"Command",
",",
"*",
"[",
"]",
"Command",
",",
"[",
"]",
"*",
"Command",
",",
"[",
"]",
"string",
")",
"{",
"var",
"chain",
"[",
"]",
"*",
"Command",
"\n",
"var",
"matches",
"[",
"]"... | // FindCommand tokenises a command line and attempts to locate the
// corresponding Command. If a matching command is found it is returned,
// along with the remaining arguments. If the command has sub-commands then
// the list of sub-commands is returned instead. A chain of matched commands
// is also returned, along ... | [
"FindCommand",
"tokenises",
"a",
"command",
"line",
"and",
"attempts",
"to",
"locate",
"the",
"corresponding",
"Command",
".",
"If",
"a",
"matching",
"command",
"is",
"found",
"it",
"is",
"returned",
"along",
"with",
"the",
"remaining",
"arguments",
".",
"If",... | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/cli/core.go#L113-L155 | train |
google/seesaw | quagga/bgp.go | String | func (s BGPState) String() string {
if name, ok := stateNames[s]; ok {
return name
}
return "Unknown"
} | go | func (s BGPState) String() string {
if name, ok := stateNames[s]; ok {
return name
}
return "Unknown"
} | [
"func",
"(",
"s",
"BGPState",
")",
"String",
"(",
")",
"string",
"{",
"if",
"name",
",",
"ok",
":=",
"stateNames",
"[",
"s",
"]",
";",
"ok",
"{",
"return",
"name",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
] | // String returns a string representation of the given BGP state. | [
"String",
"returns",
"a",
"string",
"representation",
"of",
"the",
"given",
"BGP",
"state",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/quagga/bgp.go#L60-L65 | train |
google/seesaw | quagga/bgp.go | BGPStateByName | func BGPStateByName(name string) BGPState {
name = strings.ToLower(name)
for s := range stateNames {
if strings.ToLower(stateNames[s]) == name {
return s
}
}
return BGPStateUnknown
} | go | func BGPStateByName(name string) BGPState {
name = strings.ToLower(name)
for s := range stateNames {
if strings.ToLower(stateNames[s]) == name {
return s
}
}
return BGPStateUnknown
} | [
"func",
"BGPStateByName",
"(",
"name",
"string",
")",
"BGPState",
"{",
"name",
"=",
"strings",
".",
"ToLower",
"(",
"name",
")",
"\n",
"for",
"s",
":=",
"range",
"stateNames",
"{",
"if",
"strings",
".",
"ToLower",
"(",
"stateNames",
"[",
"s",
"]",
")",... | // BGPStateByName returns the BGP state that corresponds to the given name. | [
"BGPStateByName",
"returns",
"the",
"BGP",
"state",
"that",
"corresponds",
"to",
"the",
"given",
"name",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/quagga/bgp.go#L68-L76 | train |
google/seesaw | quagga/bgp.go | NewBGP | func NewBGP(socket string, asn uint32) *BGP {
if socket == "" {
socket = BGPSocketPath
}
return &BGP{
vty: NewVTY(socket),
asn: asn,
}
} | go | func NewBGP(socket string, asn uint32) *BGP {
if socket == "" {
socket = BGPSocketPath
}
return &BGP{
vty: NewVTY(socket),
asn: asn,
}
} | [
"func",
"NewBGP",
"(",
"socket",
"string",
",",
"asn",
"uint32",
")",
"*",
"BGP",
"{",
"if",
"socket",
"==",
"\"",
"\"",
"{",
"socket",
"=",
"BGPSocketPath",
"\n",
"}",
"\n",
"return",
"&",
"BGP",
"{",
"vty",
":",
"NewVTY",
"(",
"socket",
")",
",",... | // NewBGP returns an initialised BGP structure. | [
"NewBGP",
"returns",
"an",
"initialised",
"BGP",
"structure",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/quagga/bgp.go#L156-L164 | train |
google/seesaw | quagga/bgp.go | Enable | func (b *BGP) Enable() error {
_, err := b.vty.Command("enable")
return err
} | go | func (b *BGP) Enable() error {
_, err := b.vty.Command("enable")
return err
} | [
"func",
"(",
"b",
"*",
"BGP",
")",
"Enable",
"(",
")",
"error",
"{",
"_",
",",
"err",
":=",
"b",
".",
"vty",
".",
"Command",
"(",
"\"",
"\"",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // Enable issues an "enable" command to the BGP daemon. | [
"Enable",
"issues",
"an",
"enable",
"command",
"to",
"the",
"BGP",
"daemon",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/quagga/bgp.go#L177-L180 | train |
google/seesaw | quagga/bgp.go | Configuration | func (b *BGP) Configuration() ([]string, error) {
cfg, err := b.vty.Command("write terminal")
if err != nil {
return nil, err
}
return strings.Split(cfg, "\n"), nil
} | go | func (b *BGP) Configuration() ([]string, error) {
cfg, err := b.vty.Command("write terminal")
if err != nil {
return nil, err
}
return strings.Split(cfg, "\n"), nil
} | [
"func",
"(",
"b",
"*",
"BGP",
")",
"Configuration",
"(",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"cfg",
",",
"err",
":=",
"b",
".",
"vty",
".",
"Command",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil... | // Configuration returns the current running configuration from the BGP daemon,
// as a slice of strings. | [
"Configuration",
"returns",
"the",
"current",
"running",
"configuration",
"from",
"the",
"BGP",
"daemon",
"as",
"a",
"slice",
"of",
"strings",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/quagga/bgp.go#L184-L190 | train |
google/seesaw | quagga/bgp.go | Neighbors | func (b *BGP) Neighbors() ([]*Neighbor, error) {
ni, err := b.vty.Command("show ip bgp neighbors")
if err != nil {
return nil, err
}
// TODO(jsing): Include details for advertised/received routes.
return parseNeighbors(ni), nil
} | go | func (b *BGP) Neighbors() ([]*Neighbor, error) {
ni, err := b.vty.Command("show ip bgp neighbors")
if err != nil {
return nil, err
}
// TODO(jsing): Include details for advertised/received routes.
return parseNeighbors(ni), nil
} | [
"func",
"(",
"b",
"*",
"BGP",
")",
"Neighbors",
"(",
")",
"(",
"[",
"]",
"*",
"Neighbor",
",",
"error",
")",
"{",
"ni",
",",
"err",
":=",
"b",
".",
"vty",
".",
"Command",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
... | // Neighbors returns a list of BGP neighbors that we are currently peering with. | [
"Neighbors",
"returns",
"a",
"list",
"of",
"BGP",
"neighbors",
"that",
"we",
"are",
"currently",
"peering",
"with",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/quagga/bgp.go#L193-L200 | train |
google/seesaw | quagga/bgp.go | network | func (b *BGP) network(n *net.IPNet, advertise bool) error {
var prefix string
if !advertise {
prefix = "no "
}
family := "ipv4 unicast"
if n.IP.To4() == nil {
family = "ipv6"
}
prefixLen, _ := n.Mask.Size()
cmds := []string{
"configure terminal",
fmt.Sprintf("router bgp %d", b.asn),
fmt.Sprintf("addre... | go | func (b *BGP) network(n *net.IPNet, advertise bool) error {
var prefix string
if !advertise {
prefix = "no "
}
family := "ipv4 unicast"
if n.IP.To4() == nil {
family = "ipv6"
}
prefixLen, _ := n.Mask.Size()
cmds := []string{
"configure terminal",
fmt.Sprintf("router bgp %d", b.asn),
fmt.Sprintf("addre... | [
"func",
"(",
"b",
"*",
"BGP",
")",
"network",
"(",
"n",
"*",
"net",
".",
"IPNet",
",",
"advertise",
"bool",
")",
"error",
"{",
"var",
"prefix",
"string",
"\n",
"if",
"!",
"advertise",
"{",
"prefix",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"family",
":=... | // network adds or removes a network statement from the BGP configuration. | [
"network",
"adds",
"or",
"removes",
"a",
"network",
"statement",
"from",
"the",
"BGP",
"configuration",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/quagga/bgp.go#L203-L223 | train |
google/seesaw | quagga/bgp.go | Advertise | func (b *BGP) Advertise(n *net.IPNet) error {
return b.network(n, true)
} | go | func (b *BGP) Advertise(n *net.IPNet) error {
return b.network(n, true)
} | [
"func",
"(",
"b",
"*",
"BGP",
")",
"Advertise",
"(",
"n",
"*",
"net",
".",
"IPNet",
")",
"error",
"{",
"return",
"b",
".",
"network",
"(",
"n",
",",
"true",
")",
"\n",
"}"
] | // Advertise requests the BGP daemon to advertise the specified network. | [
"Advertise",
"requests",
"the",
"BGP",
"daemon",
"to",
"advertise",
"the",
"specified",
"network",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/quagga/bgp.go#L226-L228 | train |
google/seesaw | quagga/bgp.go | Withdraw | func (b *BGP) Withdraw(n *net.IPNet) error {
return b.network(n, false)
} | go | func (b *BGP) Withdraw(n *net.IPNet) error {
return b.network(n, false)
} | [
"func",
"(",
"b",
"*",
"BGP",
")",
"Withdraw",
"(",
"n",
"*",
"net",
".",
"IPNet",
")",
"error",
"{",
"return",
"b",
".",
"network",
"(",
"n",
",",
"false",
")",
"\n",
"}"
] | // Withdraw requests the BGP daemon to withdraw advertisements for the
// specified network. | [
"Withdraw",
"requests",
"the",
"BGP",
"daemon",
"to",
"withdraw",
"advertisements",
"for",
"the",
"specified",
"network",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/quagga/bgp.go#L232-L234 | train |
google/seesaw | quagga/bgp.go | parseNeighbors | func parseNeighbors(sn string) []*Neighbor {
neighbors := make([]*Neighbor, 0)
var neighbor *Neighbor
var msgStats bool
for _, s := range strings.Split(sn, "\n") {
if nm := neighborRE.FindStringSubmatch(s); nm != nil {
asn, _ := strconv.ParseUint(nm[2], 10, 32)
neighbor = &Neighbor{
IP: net.ParseIP(nm[... | go | func parseNeighbors(sn string) []*Neighbor {
neighbors := make([]*Neighbor, 0)
var neighbor *Neighbor
var msgStats bool
for _, s := range strings.Split(sn, "\n") {
if nm := neighborRE.FindStringSubmatch(s); nm != nil {
asn, _ := strconv.ParseUint(nm[2], 10, 32)
neighbor = &Neighbor{
IP: net.ParseIP(nm[... | [
"func",
"parseNeighbors",
"(",
"sn",
"string",
")",
"[",
"]",
"*",
"Neighbor",
"{",
"neighbors",
":=",
"make",
"(",
"[",
"]",
"*",
"Neighbor",
",",
"0",
")",
"\n",
"var",
"neighbor",
"*",
"Neighbor",
"\n",
"var",
"msgStats",
"bool",
"\n",
"for",
"_",... | // parseNeighbors parses the "show ip bgp neighbors" output from the Quagga
// BGP daemon and returns a slice of Neighbor structs. | [
"parseNeighbors",
"parses",
"the",
"show",
"ip",
"bgp",
"neighbors",
"output",
"from",
"the",
"Quagga",
"BGP",
"daemon",
"and",
"returns",
"a",
"slice",
"of",
"Neighbor",
"structs",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/quagga/bgp.go#L246-L304 | train |
google/seesaw | healthcheck/udp.go | NewUDPChecker | func NewUDPChecker(ip net.IP, port int) *UDPChecker {
return &UDPChecker{
Target: Target{
IP: ip,
Port: port,
Proto: seesaw.IPProtoUDP,
},
}
} | go | func NewUDPChecker(ip net.IP, port int) *UDPChecker {
return &UDPChecker{
Target: Target{
IP: ip,
Port: port,
Proto: seesaw.IPProtoUDP,
},
}
} | [
"func",
"NewUDPChecker",
"(",
"ip",
"net",
".",
"IP",
",",
"port",
"int",
")",
"*",
"UDPChecker",
"{",
"return",
"&",
"UDPChecker",
"{",
"Target",
":",
"Target",
"{",
"IP",
":",
"ip",
",",
"Port",
":",
"port",
",",
"Proto",
":",
"seesaw",
".",
"IPP... | // NewUDPChecker returns an initialised UDPChecker. | [
"NewUDPChecker",
"returns",
"an",
"initialised",
"UDPChecker",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/udp.go#L41-L49 | train |
google/seesaw | healthcheck/udp.go | Check | func (hc *UDPChecker) Check(timeout time.Duration) *Result {
msg := fmt.Sprintf("UDP check to %s", hc.addr())
start := time.Now()
if timeout == time.Duration(0) {
timeout = defaultUDPTimeout
}
deadline := start.Add(timeout)
conn, err := dialUDP(hc.network(), hc.addr(), timeout, hc.Mark)
if err != nil {
msg ... | go | func (hc *UDPChecker) Check(timeout time.Duration) *Result {
msg := fmt.Sprintf("UDP check to %s", hc.addr())
start := time.Now()
if timeout == time.Duration(0) {
timeout = defaultUDPTimeout
}
deadline := start.Add(timeout)
conn, err := dialUDP(hc.network(), hc.addr(), timeout, hc.Mark)
if err != nil {
msg ... | [
"func",
"(",
"hc",
"*",
"UDPChecker",
")",
"Check",
"(",
"timeout",
"time",
".",
"Duration",
")",
"*",
"Result",
"{",
"msg",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"hc",
".",
"addr",
"(",
")",
")",
"\n",
"start",
":=",
"time",
".",
... | // Check executes a UDP healthcheck. | [
"Check",
"executes",
"a",
"UDP",
"healthcheck",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/udp.go#L57-L96 | train |
google/seesaw | binaries/seesaw_engine/main.go | cfgOpt | func cfgOpt(cfg *conf.ConfigFile, section, option string) string {
if !cfg.HasOption(section, option) {
return ""
}
s, err := cfg.GetString(section, option)
if err != nil {
log.Exitf("Failed to get %s for %s: %v", option, section, err)
}
return s
} | go | func cfgOpt(cfg *conf.ConfigFile, section, option string) string {
if !cfg.HasOption(section, option) {
return ""
}
s, err := cfg.GetString(section, option)
if err != nil {
log.Exitf("Failed to get %s for %s: %v", option, section, err)
}
return s
} | [
"func",
"cfgOpt",
"(",
"cfg",
"*",
"conf",
".",
"ConfigFile",
",",
"section",
",",
"option",
"string",
")",
"string",
"{",
"if",
"!",
"cfg",
".",
"HasOption",
"(",
"section",
",",
"option",
")",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"s",
",",... | // cfgOpt returns the configuration option from the specified section. If the
// option does not exist an empty string is returned. | [
"cfgOpt",
"returns",
"the",
"configuration",
"option",
"from",
"the",
"specified",
"section",
".",
"If",
"the",
"option",
"does",
"not",
"exist",
"an",
"empty",
"string",
"is",
"returned",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/binaries/seesaw_engine/main.go#L49-L58 | train |
google/seesaw | binaries/seesaw_engine/main.go | cfgIP | func cfgIP(cfg *conf.ConfigFile, section, option string) (net.IP, error) {
ipStr := cfgOpt(cfg, section, option)
if ipStr == "" {
return nil, nil
}
ip := net.ParseIP(ipStr)
if ip == nil {
return nil, fmt.Errorf("%s: %q is not a valid IP address", option, ipStr)
}
return ip, nil
} | go | func cfgIP(cfg *conf.ConfigFile, section, option string) (net.IP, error) {
ipStr := cfgOpt(cfg, section, option)
if ipStr == "" {
return nil, nil
}
ip := net.ParseIP(ipStr)
if ip == nil {
return nil, fmt.Errorf("%s: %q is not a valid IP address", option, ipStr)
}
return ip, nil
} | [
"func",
"cfgIP",
"(",
"cfg",
"*",
"conf",
".",
"ConfigFile",
",",
"section",
",",
"option",
"string",
")",
"(",
"net",
".",
"IP",
",",
"error",
")",
"{",
"ipStr",
":=",
"cfgOpt",
"(",
"cfg",
",",
"section",
",",
"option",
")",
"\n",
"if",
"ipStr",
... | // cfgIP returns configuration option from the specified section, as an IP
// address. If the option does not exist or is blank, a nil IP is returned. | [
"cfgIP",
"returns",
"configuration",
"option",
"from",
"the",
"specified",
"section",
"as",
"an",
"IP",
"address",
".",
"If",
"the",
"option",
"does",
"not",
"exist",
"or",
"is",
"blank",
"a",
"nil",
"IP",
"is",
"returned",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/binaries/seesaw_engine/main.go#L62-L72 | train |
nats-io/nats-streaming-server | server/raft_log.go | Close | func (r *raftLog) Close() error {
r.Lock()
if r.closed {
r.Unlock()
return nil
}
r.closed = true
err := r.conn.Close()
r.Unlock()
return err
} | go | func (r *raftLog) Close() error {
r.Lock()
if r.closed {
r.Unlock()
return nil
}
r.closed = true
err := r.conn.Close()
r.Unlock()
return err
} | [
"func",
"(",
"r",
"*",
"raftLog",
")",
"Close",
"(",
")",
"error",
"{",
"r",
".",
"Lock",
"(",
")",
"\n",
"if",
"r",
".",
"closed",
"{",
"r",
".",
"Unlock",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"r",
".",
"closed",
"=",
"true",
... | // Close implements the LogStore interface | [
"Close",
"implements",
"the",
"LogStore",
"interface"
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/raft_log.go#L159-L169 | train |
nats-io/nats-streaming-server | server/raft_log.go | FirstIndex | func (r *raftLog) FirstIndex() (uint64, error) {
r.RLock()
idx, err := r.getIndex(true)
r.RUnlock()
return idx, err
} | go | func (r *raftLog) FirstIndex() (uint64, error) {
r.RLock()
idx, err := r.getIndex(true)
r.RUnlock()
return idx, err
} | [
"func",
"(",
"r",
"*",
"raftLog",
")",
"FirstIndex",
"(",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"r",
".",
"RLock",
"(",
")",
"\n",
"idx",
",",
"err",
":=",
"r",
".",
"getIndex",
"(",
"true",
")",
"\n",
"r",
".",
"RUnlock",
"(",
")",
"\n... | // FirstIndex implements the LogStore interface | [
"FirstIndex",
"implements",
"the",
"LogStore",
"interface"
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/raft_log.go#L172-L177 | train |
nats-io/nats-streaming-server | server/raft_log.go | LastIndex | func (r *raftLog) LastIndex() (uint64, error) {
r.RLock()
idx, err := r.getIndex(false)
r.RUnlock()
return idx, err
} | go | func (r *raftLog) LastIndex() (uint64, error) {
r.RLock()
idx, err := r.getIndex(false)
r.RUnlock()
return idx, err
} | [
"func",
"(",
"r",
"*",
"raftLog",
")",
"LastIndex",
"(",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"r",
".",
"RLock",
"(",
")",
"\n",
"idx",
",",
"err",
":=",
"r",
".",
"getIndex",
"(",
"false",
")",
"\n",
"r",
".",
"RUnlock",
"(",
")",
"\n... | // LastIndex implements the LogStore interface | [
"LastIndex",
"implements",
"the",
"LogStore",
"interface"
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/raft_log.go#L180-L185 | train |
nats-io/nats-streaming-server | server/raft_log.go | GetLog | func (r *raftLog) GetLog(idx uint64, log *raft.Log) error {
r.RLock()
tx, err := r.conn.Begin(false)
if err != nil {
r.RUnlock()
return err
}
var key [8]byte
binary.BigEndian.PutUint64(key[:], idx)
bucket := tx.Bucket(logsBucket)
val := bucket.Get(key[:])
if val == nil {
err = raft.ErrLogNotFound
} else... | go | func (r *raftLog) GetLog(idx uint64, log *raft.Log) error {
r.RLock()
tx, err := r.conn.Begin(false)
if err != nil {
r.RUnlock()
return err
}
var key [8]byte
binary.BigEndian.PutUint64(key[:], idx)
bucket := tx.Bucket(logsBucket)
val := bucket.Get(key[:])
if val == nil {
err = raft.ErrLogNotFound
} else... | [
"func",
"(",
"r",
"*",
"raftLog",
")",
"GetLog",
"(",
"idx",
"uint64",
",",
"log",
"*",
"raft",
".",
"Log",
")",
"error",
"{",
"r",
".",
"RLock",
"(",
")",
"\n",
"tx",
",",
"err",
":=",
"r",
".",
"conn",
".",
"Begin",
"(",
"false",
")",
"\n",... | // GetLog implements the LogStore interface | [
"GetLog",
"implements",
"the",
"LogStore",
"interface"
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/raft_log.go#L212-L231 | train |
nats-io/nats-streaming-server | server/raft_log.go | StoreLog | func (r *raftLog) StoreLog(log *raft.Log) error {
return r.StoreLogs([]*raft.Log{log})
} | go | func (r *raftLog) StoreLog(log *raft.Log) error {
return r.StoreLogs([]*raft.Log{log})
} | [
"func",
"(",
"r",
"*",
"raftLog",
")",
"StoreLog",
"(",
"log",
"*",
"raft",
".",
"Log",
")",
"error",
"{",
"return",
"r",
".",
"StoreLogs",
"(",
"[",
"]",
"*",
"raft",
".",
"Log",
"{",
"log",
"}",
")",
"\n",
"}"
] | // StoreLog implements the LogStore interface | [
"StoreLog",
"implements",
"the",
"LogStore",
"interface"
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/raft_log.go#L234-L236 | train |
nats-io/nats-streaming-server | server/raft_log.go | StoreLogs | func (r *raftLog) StoreLogs(logs []*raft.Log) error {
r.Lock()
tx, err := r.conn.Begin(true)
if err != nil {
r.Unlock()
return err
}
bucket := tx.Bucket(logsBucket)
for _, log := range logs {
var (
key [8]byte
val []byte
)
binary.BigEndian.PutUint64(key[:], log.Index)
val, err = r.encodeRaftLog(... | go | func (r *raftLog) StoreLogs(logs []*raft.Log) error {
r.Lock()
tx, err := r.conn.Begin(true)
if err != nil {
r.Unlock()
return err
}
bucket := tx.Bucket(logsBucket)
for _, log := range logs {
var (
key [8]byte
val []byte
)
binary.BigEndian.PutUint64(key[:], log.Index)
val, err = r.encodeRaftLog(... | [
"func",
"(",
"r",
"*",
"raftLog",
")",
"StoreLogs",
"(",
"logs",
"[",
"]",
"*",
"raft",
".",
"Log",
")",
"error",
"{",
"r",
".",
"Lock",
"(",
")",
"\n",
"tx",
",",
"err",
":=",
"r",
".",
"conn",
".",
"Begin",
"(",
"true",
")",
"\n",
"if",
"... | // StoreLogs implements the LogStore interface | [
"StoreLogs",
"implements",
"the",
"LogStore",
"interface"
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/raft_log.go#L239-L269 | train |
nats-io/nats-streaming-server | server/raft_log.go | DeleteRange | func (r *raftLog) DeleteRange(min, max uint64) (retErr error) {
r.Lock()
defer r.Unlock()
start := time.Now()
r.log.Noticef("Deleting raft logs from %v to %v", min, max)
err := r.deleteRange(min, max)
dur := time.Since(start)
durTxt := fmt.Sprintf("Deletion took %v", dur)
if dur > 2*time.Second {
r.log.Error... | go | func (r *raftLog) DeleteRange(min, max uint64) (retErr error) {
r.Lock()
defer r.Unlock()
start := time.Now()
r.log.Noticef("Deleting raft logs from %v to %v", min, max)
err := r.deleteRange(min, max)
dur := time.Since(start)
durTxt := fmt.Sprintf("Deletion took %v", dur)
if dur > 2*time.Second {
r.log.Error... | [
"func",
"(",
"r",
"*",
"raftLog",
")",
"DeleteRange",
"(",
"min",
",",
"max",
"uint64",
")",
"(",
"retErr",
"error",
")",
"{",
"r",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"Unlock",
"(",
")",
"\n\n",
"start",
":=",
"time",
".",
"Now",
"... | // DeleteRange implements the LogStore interface | [
"DeleteRange",
"implements",
"the",
"LogStore",
"interface"
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/raft_log.go#L272-L287 | train |
nats-io/nats-streaming-server | server/raft_log.go | Set | func (r *raftLog) Set(k, v []byte) error {
r.Lock()
tx, err := r.conn.Begin(true)
if err != nil {
r.Unlock()
return err
}
bucket := tx.Bucket(confBucket)
err = bucket.Put(k, v)
if err != nil {
tx.Rollback()
} else {
err = tx.Commit()
}
r.Unlock()
return err
} | go | func (r *raftLog) Set(k, v []byte) error {
r.Lock()
tx, err := r.conn.Begin(true)
if err != nil {
r.Unlock()
return err
}
bucket := tx.Bucket(confBucket)
err = bucket.Put(k, v)
if err != nil {
tx.Rollback()
} else {
err = tx.Commit()
}
r.Unlock()
return err
} | [
"func",
"(",
"r",
"*",
"raftLog",
")",
"Set",
"(",
"k",
",",
"v",
"[",
"]",
"byte",
")",
"error",
"{",
"r",
".",
"Lock",
"(",
")",
"\n",
"tx",
",",
"err",
":=",
"r",
".",
"conn",
".",
"Begin",
"(",
"true",
")",
"\n",
"if",
"err",
"!=",
"n... | // Set implements the Stable interface | [
"Set",
"implements",
"the",
"Stable",
"interface"
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/raft_log.go#L314-L330 | train |
nats-io/nats-streaming-server | server/raft_log.go | Get | func (r *raftLog) Get(k []byte) ([]byte, error) {
r.RLock()
tx, err := r.conn.Begin(false)
if err != nil {
r.RUnlock()
return nil, err
}
var v []byte
bucket := tx.Bucket(confBucket)
val := bucket.Get(k)
if val == nil {
err = errKeyNotFound
} else {
// Make a copy
v = append([]byte(nil), val...)
}
t... | go | func (r *raftLog) Get(k []byte) ([]byte, error) {
r.RLock()
tx, err := r.conn.Begin(false)
if err != nil {
r.RUnlock()
return nil, err
}
var v []byte
bucket := tx.Bucket(confBucket)
val := bucket.Get(k)
if val == nil {
err = errKeyNotFound
} else {
// Make a copy
v = append([]byte(nil), val...)
}
t... | [
"func",
"(",
"r",
"*",
"raftLog",
")",
"Get",
"(",
"k",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"r",
".",
"RLock",
"(",
")",
"\n",
"tx",
",",
"err",
":=",
"r",
".",
"conn",
".",
"Begin",
"(",
"false",
")",
"\... | // Get implements the Stable interface | [
"Get",
"implements",
"the",
"Stable",
"interface"
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/raft_log.go#L333-L352 | train |
nats-io/nats-streaming-server | server/raft_log.go | SetUint64 | func (r *raftLog) SetUint64(k []byte, v uint64) error {
var vbytes [8]byte
binary.BigEndian.PutUint64(vbytes[:], v)
err := r.Set(k, vbytes[:])
return err
} | go | func (r *raftLog) SetUint64(k []byte, v uint64) error {
var vbytes [8]byte
binary.BigEndian.PutUint64(vbytes[:], v)
err := r.Set(k, vbytes[:])
return err
} | [
"func",
"(",
"r",
"*",
"raftLog",
")",
"SetUint64",
"(",
"k",
"[",
"]",
"byte",
",",
"v",
"uint64",
")",
"error",
"{",
"var",
"vbytes",
"[",
"8",
"]",
"byte",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint64",
"(",
"vbytes",
"[",
":",
"]",
",",
... | // SetUint64 implements the Stable interface | [
"SetUint64",
"implements",
"the",
"Stable",
"interface"
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/raft_log.go#L355-L360 | train |
nats-io/nats-streaming-server | server/raft_log.go | GetUint64 | func (r *raftLog) GetUint64(k []byte) (uint64, error) {
var v uint64
vbytes, err := r.Get(k)
if err == nil {
v = binary.BigEndian.Uint64(vbytes)
}
return v, err
} | go | func (r *raftLog) GetUint64(k []byte) (uint64, error) {
var v uint64
vbytes, err := r.Get(k)
if err == nil {
v = binary.BigEndian.Uint64(vbytes)
}
return v, err
} | [
"func",
"(",
"r",
"*",
"raftLog",
")",
"GetUint64",
"(",
"k",
"[",
"]",
"byte",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"var",
"v",
"uint64",
"\n",
"vbytes",
",",
"err",
":=",
"r",
".",
"Get",
"(",
"k",
")",
"\n",
"if",
"err",
"==",
"nil"... | // GetUint64 implements the Stable interface | [
"GetUint64",
"implements",
"the",
"Stable",
"interface"
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/raft_log.go#L363-L370 | train |
nats-io/nats-streaming-server | server/snapshot.go | Restore | func (r *raftFSM) Restore(snapshot io.ReadCloser) (retErr error) {
s := r.server
defer snapshot.Close()
r.Lock()
defer r.Unlock()
// This function may be invoked directly from raft.NewRaft() when
// the node is initialized and if there were exisiting local snapshots,
// or later, when catching up with a leader... | go | func (r *raftFSM) Restore(snapshot io.ReadCloser) (retErr error) {
s := r.server
defer snapshot.Close()
r.Lock()
defer r.Unlock()
// This function may be invoked directly from raft.NewRaft() when
// the node is initialized and if there were exisiting local snapshots,
// or later, when catching up with a leader... | [
"func",
"(",
"r",
"*",
"raftFSM",
")",
"Restore",
"(",
"snapshot",
"io",
".",
"ReadCloser",
")",
"(",
"retErr",
"error",
")",
"{",
"s",
":=",
"r",
".",
"server",
"\n",
"defer",
"snapshot",
".",
"Close",
"(",
")",
"\n\n",
"r",
".",
"Lock",
"(",
")... | // Restore is used to restore an FSM from a snapshot. It is not called
// concurrently with any other command. The FSM must discard all previous
// state. | [
"Restore",
"is",
"used",
"to",
"restore",
"an",
"FSM",
"from",
"a",
"snapshot",
".",
"It",
"is",
"not",
"called",
"concurrently",
"with",
"any",
"other",
"command",
".",
"The",
"FSM",
"must",
"discard",
"all",
"previous",
"state",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/snapshot.go#L225-L305 | train |
nats-io/nats-streaming-server | stores/raftstore.go | NewRaftStore | func NewRaftStore(log logger.Logger, s Store, limits *StoreLimits) *RaftStore {
return &RaftStore{Store: s, log: log}
} | go | func NewRaftStore(log logger.Logger, s Store, limits *StoreLimits) *RaftStore {
return &RaftStore{Store: s, log: log}
} | [
"func",
"NewRaftStore",
"(",
"log",
"logger",
".",
"Logger",
",",
"s",
"Store",
",",
"limits",
"*",
"StoreLimits",
")",
"*",
"RaftStore",
"{",
"return",
"&",
"RaftStore",
"{",
"Store",
":",
"s",
",",
"log",
":",
"log",
"}",
"\n",
"}"
] | // NewRaftStore returns an instarce of a RaftStore | [
"NewRaftStore",
"returns",
"an",
"instarce",
"of",
"a",
"RaftStore"
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/raftstore.go#L40-L42 | train |
nats-io/nats-streaming-server | stores/common.go | setLimits | func (gs *genericStore) setLimits(limits *StoreLimits) error {
// Make a copy.
gs.limits = limits.Clone()
// Build will validate and apply inheritance if no error.
if err := gs.limits.Build(); err != nil {
return err
}
// We don't need the PerChannel map and the sublist. So replace
// the map with the sublist ... | go | func (gs *genericStore) setLimits(limits *StoreLimits) error {
// Make a copy.
gs.limits = limits.Clone()
// Build will validate and apply inheritance if no error.
if err := gs.limits.Build(); err != nil {
return err
}
// We don't need the PerChannel map and the sublist. So replace
// the map with the sublist ... | [
"func",
"(",
"gs",
"*",
"genericStore",
")",
"setLimits",
"(",
"limits",
"*",
"StoreLimits",
")",
"error",
"{",
"// Make a copy.",
"gs",
".",
"limits",
"=",
"limits",
".",
"Clone",
"(",
")",
"\n",
"// Build will validate and apply inheritance if no error.",
"if",
... | // setLimits makes a copy of the given StoreLimits,
// validates the limits and if ok, applies the inheritance. | [
"setLimits",
"makes",
"a",
"copy",
"of",
"the",
"given",
"StoreLimits",
"validates",
"the",
"limits",
"and",
"if",
"ok",
"applies",
"the",
"inheritance",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/common.go#L115-L133 | train |
nats-io/nats-streaming-server | stores/common.go | getChannelLimits | func (gs *genericStore) getChannelLimits(channel string) *ChannelLimits {
r := gs.sublist.Match(channel)
if len(r) == 0 {
// If there is no match, that means we need to use the global limits.
return &gs.limits.ChannelLimits
}
// If there is a match, use the limits from the last element because
// we know that ... | go | func (gs *genericStore) getChannelLimits(channel string) *ChannelLimits {
r := gs.sublist.Match(channel)
if len(r) == 0 {
// If there is no match, that means we need to use the global limits.
return &gs.limits.ChannelLimits
}
// If there is a match, use the limits from the last element because
// we know that ... | [
"func",
"(",
"gs",
"*",
"genericStore",
")",
"getChannelLimits",
"(",
"channel",
"string",
")",
"*",
"ChannelLimits",
"{",
"r",
":=",
"gs",
".",
"sublist",
".",
"Match",
"(",
"channel",
")",
"\n",
"if",
"len",
"(",
"r",
")",
"==",
"0",
"{",
"// If th... | // Returns the appropriate limits for this channel based on inheritance.
// The channel is assumed to be a literal, and the store lock held on entry. | [
"Returns",
"the",
"appropriate",
"limits",
"for",
"this",
"channel",
"based",
"on",
"inheritance",
".",
"The",
"channel",
"is",
"assumed",
"to",
"be",
"a",
"literal",
"and",
"the",
"store",
"lock",
"held",
"on",
"entry",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/common.go#L137-L148 | train |
nats-io/nats-streaming-server | stores/common.go | GetChannelLimits | func (gs *genericStore) GetChannelLimits(channel string) *ChannelLimits {
gs.RLock()
defer gs.RUnlock()
c := gs.channels[channel]
if c == nil {
return nil
}
// Return a copy
cl := *gs.getChannelLimits(channel)
return &cl
} | go | func (gs *genericStore) GetChannelLimits(channel string) *ChannelLimits {
gs.RLock()
defer gs.RUnlock()
c := gs.channels[channel]
if c == nil {
return nil
}
// Return a copy
cl := *gs.getChannelLimits(channel)
return &cl
} | [
"func",
"(",
"gs",
"*",
"genericStore",
")",
"GetChannelLimits",
"(",
"channel",
"string",
")",
"*",
"ChannelLimits",
"{",
"gs",
".",
"RLock",
"(",
")",
"\n",
"defer",
"gs",
".",
"RUnlock",
"(",
")",
"\n",
"c",
":=",
"gs",
".",
"channels",
"[",
"chan... | // GetChannelLimits implements the Store interface | [
"GetChannelLimits",
"implements",
"the",
"Store",
"interface"
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/common.go#L151-L161 | train |
nats-io/nats-streaming-server | stores/common.go | SetLimits | func (gs *genericStore) SetLimits(limits *StoreLimits) error {
gs.Lock()
err := gs.setLimits(limits)
gs.Unlock()
return err
} | go | func (gs *genericStore) SetLimits(limits *StoreLimits) error {
gs.Lock()
err := gs.setLimits(limits)
gs.Unlock()
return err
} | [
"func",
"(",
"gs",
"*",
"genericStore",
")",
"SetLimits",
"(",
"limits",
"*",
"StoreLimits",
")",
"error",
"{",
"gs",
".",
"Lock",
"(",
")",
"\n",
"err",
":=",
"gs",
".",
"setLimits",
"(",
"limits",
")",
"\n",
"gs",
".",
"Unlock",
"(",
")",
"\n",
... | // SetLimits sets limits for this store | [
"SetLimits",
"sets",
"limits",
"for",
"this",
"store"
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/common.go#L164-L169 | train |
nats-io/nats-streaming-server | stores/common.go | canAddChannel | func (gs *genericStore) canAddChannel(name string) error {
if gs.channels[name] != nil {
return ErrAlreadyExists
}
if gs.limits.MaxChannels > 0 && len(gs.channels) >= gs.limits.MaxChannels {
return ErrTooManyChannels
}
return nil
} | go | func (gs *genericStore) canAddChannel(name string) error {
if gs.channels[name] != nil {
return ErrAlreadyExists
}
if gs.limits.MaxChannels > 0 && len(gs.channels) >= gs.limits.MaxChannels {
return ErrTooManyChannels
}
return nil
} | [
"func",
"(",
"gs",
"*",
"genericStore",
")",
"canAddChannel",
"(",
"name",
"string",
")",
"error",
"{",
"if",
"gs",
".",
"channels",
"[",
"name",
"]",
"!=",
"nil",
"{",
"return",
"ErrAlreadyExists",
"\n",
"}",
"\n",
"if",
"gs",
".",
"limits",
".",
"M... | // canAddChannel returns true if the current number of channels is below the limit.
// If a channel named `channelName` alreadt exists, an error is returned.
// Store lock is assumed to be locked. | [
"canAddChannel",
"returns",
"true",
"if",
"the",
"current",
"number",
"of",
"channels",
"is",
"below",
"the",
"limit",
".",
"If",
"a",
"channel",
"named",
"channelName",
"alreadt",
"exists",
"an",
"error",
"is",
"returned",
".",
"Store",
"lock",
"is",
"assum... | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/common.go#L203-L211 | train |
nats-io/nats-streaming-server | stores/common.go | Close | func (gs *genericStore) Close() error {
gs.Lock()
defer gs.Unlock()
if gs.closed {
return nil
}
gs.closed = true
return gs.close()
} | go | func (gs *genericStore) Close() error {
gs.Lock()
defer gs.Unlock()
if gs.closed {
return nil
}
gs.closed = true
return gs.close()
} | [
"func",
"(",
"gs",
"*",
"genericStore",
")",
"Close",
"(",
")",
"error",
"{",
"gs",
".",
"Lock",
"(",
")",
"\n",
"defer",
"gs",
".",
"Unlock",
"(",
")",
"\n",
"if",
"gs",
".",
"closed",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"gs",
".",
"closed"... | // Close closes all stores | [
"Close",
"closes",
"all",
"stores"
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/common.go#L224-L232 | train |
nats-io/nats-streaming-server | stores/common.go | close | func (gs *genericStore) close() error {
var err error
var lerr error
for _, cs := range gs.channels {
lerr = cs.Subs.Close()
if lerr != nil && err == nil {
err = lerr
}
lerr = cs.Msgs.Close()
if lerr != nil && err == nil {
err = lerr
}
}
return err
} | go | func (gs *genericStore) close() error {
var err error
var lerr error
for _, cs := range gs.channels {
lerr = cs.Subs.Close()
if lerr != nil && err == nil {
err = lerr
}
lerr = cs.Msgs.Close()
if lerr != nil && err == nil {
err = lerr
}
}
return err
} | [
"func",
"(",
"gs",
"*",
"genericStore",
")",
"close",
"(",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"var",
"lerr",
"error",
"\n\n",
"for",
"_",
",",
"cs",
":=",
"range",
"gs",
".",
"channels",
"{",
"lerr",
"=",
"cs",
".",
"Subs",
".",
"Clo... | // close closes all stores. Store lock is assumed held on entry | [
"close",
"closes",
"all",
"stores",
".",
"Store",
"lock",
"is",
"assumed",
"held",
"on",
"entry"
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/common.go#L235-L250 | train |
nats-io/nats-streaming-server | stores/common.go | State | func (gms *genericMsgStore) State() (numMessages int, byteSize uint64, err error) {
gms.RLock()
c, b := gms.totalCount, gms.totalBytes
gms.RUnlock()
return c, b, nil
} | go | func (gms *genericMsgStore) State() (numMessages int, byteSize uint64, err error) {
gms.RLock()
c, b := gms.totalCount, gms.totalBytes
gms.RUnlock()
return c, b, nil
} | [
"func",
"(",
"gms",
"*",
"genericMsgStore",
")",
"State",
"(",
")",
"(",
"numMessages",
"int",
",",
"byteSize",
"uint64",
",",
"err",
"error",
")",
"{",
"gms",
".",
"RLock",
"(",
")",
"\n",
"c",
",",
"b",
":=",
"gms",
".",
"totalCount",
",",
"gms",... | // State returns some statistics related to this store | [
"State",
"returns",
"some",
"statistics",
"related",
"to",
"this",
"store"
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/common.go#L264-L269 | train |
nats-io/nats-streaming-server | stores/common.go | FirstSequence | func (gms *genericMsgStore) FirstSequence() (uint64, error) {
gms.RLock()
first := gms.first
gms.RUnlock()
return first, nil
} | go | func (gms *genericMsgStore) FirstSequence() (uint64, error) {
gms.RLock()
first := gms.first
gms.RUnlock()
return first, nil
} | [
"func",
"(",
"gms",
"*",
"genericMsgStore",
")",
"FirstSequence",
"(",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"gms",
".",
"RLock",
"(",
")",
"\n",
"first",
":=",
"gms",
".",
"first",
"\n",
"gms",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"firs... | // FirstSequence returns sequence for first message stored. | [
"FirstSequence",
"returns",
"sequence",
"for",
"first",
"message",
"stored",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/common.go#L278-L283 | train |
nats-io/nats-streaming-server | stores/common.go | LastSequence | func (gms *genericMsgStore) LastSequence() (uint64, error) {
gms.RLock()
last := gms.last
gms.RUnlock()
return last, nil
} | go | func (gms *genericMsgStore) LastSequence() (uint64, error) {
gms.RLock()
last := gms.last
gms.RUnlock()
return last, nil
} | [
"func",
"(",
"gms",
"*",
"genericMsgStore",
")",
"LastSequence",
"(",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"gms",
".",
"RLock",
"(",
")",
"\n",
"last",
":=",
"gms",
".",
"last",
"\n",
"gms",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"last",
... | // LastSequence returns sequence for last message stored. | [
"LastSequence",
"returns",
"sequence",
"for",
"last",
"message",
"stored",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/common.go#L286-L291 | train |
nats-io/nats-streaming-server | stores/common.go | FirstAndLastSequence | func (gms *genericMsgStore) FirstAndLastSequence() (uint64, uint64, error) {
gms.RLock()
first, last := gms.first, gms.last
gms.RUnlock()
return first, last, nil
} | go | func (gms *genericMsgStore) FirstAndLastSequence() (uint64, uint64, error) {
gms.RLock()
first, last := gms.first, gms.last
gms.RUnlock()
return first, last, nil
} | [
"func",
"(",
"gms",
"*",
"genericMsgStore",
")",
"FirstAndLastSequence",
"(",
")",
"(",
"uint64",
",",
"uint64",
",",
"error",
")",
"{",
"gms",
".",
"RLock",
"(",
")",
"\n",
"first",
",",
"last",
":=",
"gms",
".",
"first",
",",
"gms",
".",
"last",
... | // FirstAndLastSequence returns sequences for the first and last messages stored. | [
"FirstAndLastSequence",
"returns",
"sequences",
"for",
"the",
"first",
"and",
"last",
"messages",
"stored",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/common.go#L294-L299 | train |
nats-io/nats-streaming-server | stores/common.go | CreateSub | func (gss *genericSubStore) CreateSub(sub *spb.SubState) error {
gss.Lock()
err := gss.createSub(sub)
gss.Unlock()
return err
} | go | func (gss *genericSubStore) CreateSub(sub *spb.SubState) error {
gss.Lock()
err := gss.createSub(sub)
gss.Unlock()
return err
} | [
"func",
"(",
"gss",
"*",
"genericSubStore",
")",
"CreateSub",
"(",
"sub",
"*",
"spb",
".",
"SubState",
")",
"error",
"{",
"gss",
".",
"Lock",
"(",
")",
"\n",
"err",
":=",
"gss",
".",
"createSub",
"(",
"sub",
")",
"\n",
"gss",
".",
"Unlock",
"(",
... | // CreateSub records a new subscription represented by SubState. On success,
// it records the subscription's ID in SubState.ID. This ID is to be used
// by the other SubStore methods. | [
"CreateSub",
"records",
"a",
"new",
"subscription",
"represented",
"by",
"SubState",
".",
"On",
"success",
"it",
"records",
"the",
"subscription",
"s",
"ID",
"in",
"SubState",
".",
"ID",
".",
"This",
"ID",
"is",
"to",
"be",
"used",
"by",
"the",
"other",
... | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/common.go#L354-L359 | train |
nats-io/nats-streaming-server | stores/common.go | createSub | func (gss *genericSubStore) createSub(sub *spb.SubState) error {
if gss.limits.MaxSubscriptions > 0 && len(gss.subs) >= gss.limits.MaxSubscriptions {
return ErrTooManySubs
}
// Bump the max value before assigning it to the new subscription.
gss.maxSubID++
// This new subscription has the max value.
sub.ID = g... | go | func (gss *genericSubStore) createSub(sub *spb.SubState) error {
if gss.limits.MaxSubscriptions > 0 && len(gss.subs) >= gss.limits.MaxSubscriptions {
return ErrTooManySubs
}
// Bump the max value before assigning it to the new subscription.
gss.maxSubID++
// This new subscription has the max value.
sub.ID = g... | [
"func",
"(",
"gss",
"*",
"genericSubStore",
")",
"createSub",
"(",
"sub",
"*",
"spb",
".",
"SubState",
")",
"error",
"{",
"if",
"gss",
".",
"limits",
".",
"MaxSubscriptions",
">",
"0",
"&&",
"len",
"(",
"gss",
".",
"subs",
")",
">=",
"gss",
".",
"l... | // createSub checks that the number of subscriptions is below the max
// and if so, assigns a new subscription ID and keep track of it in a map.
// Lock is assumed to be held on entry. | [
"createSub",
"checks",
"that",
"the",
"number",
"of",
"subscriptions",
"is",
"below",
"the",
"max",
"and",
"if",
"so",
"assigns",
"a",
"new",
"subscription",
"ID",
"and",
"keep",
"track",
"of",
"it",
"in",
"a",
"map",
".",
"Lock",
"is",
"assumed",
"to",
... | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/common.go#L369-L384 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.