repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
google/seesaw
netlink/netlink.go
uint32FromNetwork
func uint32FromNetwork(u uint32) uint32 { b := *(*[4]byte)(unsafe.Pointer(&u)) return binary.BigEndian.Uint32(b[:]) }
go
func uint32FromNetwork(u uint32) uint32 { b := *(*[4]byte)(unsafe.Pointer(&u)) return binary.BigEndian.Uint32(b[:]) }
[ "func", "uint32FromNetwork", "(", "u", "uint32", ")", "uint32", "{", "b", ":=", "*", "(", "*", "[", "4", "]", "byte", ")", "(", "unsafe", ".", "Pointer", "(", "&", "u", ")", ")", "\n", "return", "binary", ".", "BigEndian", ".", "Uint32", "(", "b", "[", ":", "]", ")", "\n", "}" ]
// uint32FromNetwork converts the given value from its network byte order.
[ "uint32FromNetwork", "converts", "the", "given", "value", "from", "its", "network", "byte", "order", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/netlink/netlink.go#L61-L64
train
google/seesaw
netlink/netlink.go
uint32ToNetwork
func uint32ToNetwork(u uint32) uint32 { var b [4]byte binary.BigEndian.PutUint32(b[:], u) return *(*uint32)(unsafe.Pointer(&b)) }
go
func uint32ToNetwork(u uint32) uint32 { var b [4]byte binary.BigEndian.PutUint32(b[:], u) return *(*uint32)(unsafe.Pointer(&b)) }
[ "func", "uint32ToNetwork", "(", "u", "uint32", ")", "uint32", "{", "var", "b", "[", "4", "]", "byte", "\n", "binary", ".", "BigEndian", ".", "PutUint32", "(", "b", "[", ":", "]", ",", "u", ")", "\n", "return", "*", "(", "*", "uint32", ")", "(", "unsafe", ".", "Pointer", "(", "&", "b", ")", ")", "\n", "}" ]
// uint32ToNetwork converts the given value to its network byte order.
[ "uint32ToNetwork", "converts", "the", "given", "value", "to", "its", "network", "byte", "order", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/netlink/netlink.go#L67-L71
train
google/seesaw
netlink/netlink.go
uint64FromNetwork
func uint64FromNetwork(u uint64) uint64 { b := *(*[8]byte)(unsafe.Pointer(&u)) return binary.BigEndian.Uint64(b[:]) }
go
func uint64FromNetwork(u uint64) uint64 { b := *(*[8]byte)(unsafe.Pointer(&u)) return binary.BigEndian.Uint64(b[:]) }
[ "func", "uint64FromNetwork", "(", "u", "uint64", ")", "uint64", "{", "b", ":=", "*", "(", "*", "[", "8", "]", "byte", ")", "(", "unsafe", ".", "Pointer", "(", "&", "u", ")", ")", "\n", "return", "binary", ".", "BigEndian", ".", "Uint64", "(", "b", "[", ":", "]", ")", "\n", "}" ]
// uint64FromNetwork converts the given value from its network byte order.
[ "uint64FromNetwork", "converts", "the", "given", "value", "from", "its", "network", "byte", "order", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/netlink/netlink.go#L74-L77
train
google/seesaw
netlink/netlink.go
uint64ToNetwork
func uint64ToNetwork(u uint64) uint64 { var b [8]byte binary.BigEndian.PutUint64(b[:], u) return *(*uint64)(unsafe.Pointer(&b)) }
go
func uint64ToNetwork(u uint64) uint64 { var b [8]byte binary.BigEndian.PutUint64(b[:], u) return *(*uint64)(unsafe.Pointer(&b)) }
[ "func", "uint64ToNetwork", "(", "u", "uint64", ")", "uint64", "{", "var", "b", "[", "8", "]", "byte", "\n", "binary", ".", "BigEndian", ".", "PutUint64", "(", "b", "[", ":", "]", ",", "u", ")", "\n", "return", "*", "(", "*", "uint64", ")", "(", "unsafe", ".", "Pointer", "(", "&", "b", ")", ")", "\n", "}" ]
// uint64ToNetwork converts the given value to its network byte order.
[ "uint64ToNetwork", "converts", "the", "given", "value", "to", "its", "network", "byte", "order", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/netlink/netlink.go#L80-L84
train
google/seesaw
netlink/netlink.go
structMaxAttrID
func structMaxAttrID(v reflect.Value) (uint16, error) { if v.Kind() != reflect.Struct { return 0, fmt.Errorf("%v is not a struct", v.Type()) } st := v.Type() var maxAttrID uint16 for i := 0; i < st.NumField(); i++ { ft, fv := st.Field(i), v.Field(i) fp, err := parseFieldParams(ft.Tag.Get("netlink")) if err != nil { return 0, err } if fp != nil && fp.attr > maxAttrID { maxAttrID = fp.attr } if fp == nil && fv.Kind() == reflect.Struct { attrID, err := structMaxAttrID(fv) if err != nil { return 0, err } if attrID > maxAttrID { maxAttrID = attrID } } } return maxAttrID, nil }
go
func structMaxAttrID(v reflect.Value) (uint16, error) { if v.Kind() != reflect.Struct { return 0, fmt.Errorf("%v is not a struct", v.Type()) } st := v.Type() var maxAttrID uint16 for i := 0; i < st.NumField(); i++ { ft, fv := st.Field(i), v.Field(i) fp, err := parseFieldParams(ft.Tag.Get("netlink")) if err != nil { return 0, err } if fp != nil && fp.attr > maxAttrID { maxAttrID = fp.attr } if fp == nil && fv.Kind() == reflect.Struct { attrID, err := structMaxAttrID(fv) if err != nil { return 0, err } if attrID > maxAttrID { maxAttrID = attrID } } } return maxAttrID, nil }
[ "func", "structMaxAttrID", "(", "v", "reflect", ".", "Value", ")", "(", "uint16", ",", "error", ")", "{", "if", "v", ".", "Kind", "(", ")", "!=", "reflect", ".", "Struct", "{", "return", "0", ",", "fmt", ".", "Errorf", "(", "\"%v is not a struct\"", ",", "v", ".", "Type", "(", ")", ")", "\n", "}", "\n", "st", ":=", "v", ".", "Type", "(", ")", "\n", "var", "maxAttrID", "uint16", "\n", "for", "i", ":=", "0", ";", "i", "<", "st", ".", "NumField", "(", ")", ";", "i", "++", "{", "ft", ",", "fv", ":=", "st", ".", "Field", "(", "i", ")", ",", "v", ".", "Field", "(", "i", ")", "\n", "fp", ",", "err", ":=", "parseFieldParams", "(", "ft", ".", "Tag", ".", "Get", "(", "\"netlink\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "if", "fp", "!=", "nil", "&&", "fp", ".", "attr", ">", "maxAttrID", "{", "maxAttrID", "=", "fp", ".", "attr", "\n", "}", "\n", "if", "fp", "==", "nil", "&&", "fv", ".", "Kind", "(", ")", "==", "reflect", ".", "Struct", "{", "attrID", ",", "err", ":=", "structMaxAttrID", "(", "fv", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "if", "attrID", ">", "maxAttrID", "{", "maxAttrID", "=", "attrID", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "maxAttrID", ",", "nil", "\n", "}" ]
// structMaxAttrID returns the maximum attribute ID found on netlink tagged // fields within the given struct and any untagged structs it contains.
[ "structMaxAttrID", "returns", "the", "maximum", "attribute", "ID", "found", "on", "netlink", "tagged", "fields", "within", "the", "given", "struct", "and", "any", "untagged", "structs", "it", "contains", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/netlink/netlink.go#L130-L157
train
google/seesaw
netlink/netlink.go
Error
func (e *Error) Error() string { nle := C.GoString(C.nl_geterror(e.errno)) return fmt.Sprintf("%s: %s", e.msg, strings.ToLower(nle)) }
go
func (e *Error) Error() string { nle := C.GoString(C.nl_geterror(e.errno)) return fmt.Sprintf("%s: %s", e.msg, strings.ToLower(nle)) }
[ "func", "(", "e", "*", "Error", ")", "Error", "(", ")", "string", "{", "nle", ":=", "C", ".", "GoString", "(", "C", ".", "nl_geterror", "(", "e", ".", "errno", ")", ")", "\n", "return", "fmt", ".", "Sprintf", "(", "\"%s: %s\"", ",", "e", ".", "msg", ",", "strings", ".", "ToLower", "(", "nle", ")", ")", "\n", "}" ]
// Error returns the string representation of a netlink error.
[ "Error", "returns", "the", "string", "representation", "of", "a", "netlink", "error", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/netlink/netlink.go#L539-L542
train
google/seesaw
netlink/netlink.go
Family
func Family(name string) (int, error) { s, err := newSocket() if err != nil { return -1, err } defer s.free() if errno := C.genl_connect(s.nls); errno != 0 { return -1, &Error{errno, "failed to connect to netlink"} } defer C.nl_close((*C.struct_nl_sock)(s.nls)) cn := C.CString(name) defer C.free(unsafe.Pointer(cn)) family := C.genl_ctrl_resolve(s.nls, cn) if family < 0 { return -1, errors.New("failed to resolve family name") } return int(family), nil }
go
func Family(name string) (int, error) { s, err := newSocket() if err != nil { return -1, err } defer s.free() if errno := C.genl_connect(s.nls); errno != 0 { return -1, &Error{errno, "failed to connect to netlink"} } defer C.nl_close((*C.struct_nl_sock)(s.nls)) cn := C.CString(name) defer C.free(unsafe.Pointer(cn)) family := C.genl_ctrl_resolve(s.nls, cn) if family < 0 { return -1, errors.New("failed to resolve family name") } return int(family), nil }
[ "func", "Family", "(", "name", "string", ")", "(", "int", ",", "error", ")", "{", "s", ",", "err", ":=", "newSocket", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "err", "\n", "}", "\n", "defer", "s", ".", "free", "(", ")", "\n", "if", "errno", ":=", "C", ".", "genl_connect", "(", "s", ".", "nls", ")", ";", "errno", "!=", "0", "{", "return", "-", "1", ",", "&", "Error", "{", "errno", ",", "\"failed to connect to netlink\"", "}", "\n", "}", "\n", "defer", "C", ".", "nl_close", "(", "(", "*", "C", ".", "struct_nl_sock", ")", "(", "s", ".", "nls", ")", ")", "\n", "cn", ":=", "C", ".", "CString", "(", "name", ")", "\n", "defer", "C", ".", "free", "(", "unsafe", ".", "Pointer", "(", "cn", ")", ")", "\n", "family", ":=", "C", ".", "genl_ctrl_resolve", "(", "s", ".", "nls", ",", "cn", ")", "\n", "if", "family", "<", "0", "{", "return", "-", "1", ",", "errors", ".", "New", "(", "\"failed to resolve family name\"", ")", "\n", "}", "\n", "return", "int", "(", "family", ")", ",", "nil", "\n", "}" ]
// Family returns the family identifier for the specified family name.
[ "Family", "returns", "the", "family", "identifier", "for", "the", "specified", "family", "name", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/netlink/netlink.go#L545-L564
train
google/seesaw
ncc/ip.go
validateInterface
func validateInterface(iface *net.Interface) error { if !ifaceNameRegexp.MatchString(iface.Name) { return fmt.Errorf("Invalid interface name %q", iface.Name) } return nil }
go
func validateInterface(iface *net.Interface) error { if !ifaceNameRegexp.MatchString(iface.Name) { return fmt.Errorf("Invalid interface name %q", iface.Name) } return nil }
[ "func", "validateInterface", "(", "iface", "*", "net", ".", "Interface", ")", "error", "{", "if", "!", "ifaceNameRegexp", ".", "MatchString", "(", "iface", ".", "Name", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"Invalid interface name %q\"", ",", "iface", ".", "Name", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// validateInterface validates the name of a network interface.
[ "validateInterface", "validates", "the", "name", "of", "a", "network", "interface", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ip.go#L45-L50
train
google/seesaw
ncc/ip.go
ifaceDown
func ifaceDown(pIface *net.Interface) error { out, err := ipRunOutput("link show dev %s", pIface.Name) if !strings.Contains(out, "state UP") { return nil } // Unlike IPv4, the kernel removes IPv6 addresses when the link goes down. We // don't want that behavior, so we have to preserve the addresses manually. // TODO(angusc): See if we can get a sysctl or something added to the kernel // so we can avoid doing this. ipv6Addrs := make(map[string]*net.Interface) ifaces, err := vlanInterfaces(pIface) if err != nil { return err } ifaces = append(ifaces, pIface) for _, iface := range ifaces { out, err = ipRunOutput("-6 addr show dev %s scope global", iface.Name) for _, line := range strings.Split(out, "\n") { if match := ipv6AddrRegexp.FindStringSubmatch(line); match != nil { ipv6Addrs[match[1]] = iface } } } if err := ifaceFastDown(pIface); err != nil { return err } for addr, iface := range ipv6Addrs { if err := ipRunIface(iface, "addr add %s dev %s", addr, iface.Name); err != nil { return err } } return nil }
go
func ifaceDown(pIface *net.Interface) error { out, err := ipRunOutput("link show dev %s", pIface.Name) if !strings.Contains(out, "state UP") { return nil } // Unlike IPv4, the kernel removes IPv6 addresses when the link goes down. We // don't want that behavior, so we have to preserve the addresses manually. // TODO(angusc): See if we can get a sysctl or something added to the kernel // so we can avoid doing this. ipv6Addrs := make(map[string]*net.Interface) ifaces, err := vlanInterfaces(pIface) if err != nil { return err } ifaces = append(ifaces, pIface) for _, iface := range ifaces { out, err = ipRunOutput("-6 addr show dev %s scope global", iface.Name) for _, line := range strings.Split(out, "\n") { if match := ipv6AddrRegexp.FindStringSubmatch(line); match != nil { ipv6Addrs[match[1]] = iface } } } if err := ifaceFastDown(pIface); err != nil { return err } for addr, iface := range ipv6Addrs { if err := ipRunIface(iface, "addr add %s dev %s", addr, iface.Name); err != nil { return err } } return nil }
[ "func", "ifaceDown", "(", "pIface", "*", "net", ".", "Interface", ")", "error", "{", "out", ",", "err", ":=", "ipRunOutput", "(", "\"link show dev %s\"", ",", "pIface", ".", "Name", ")", "\n", "if", "!", "strings", ".", "Contains", "(", "out", ",", "\"state UP\"", ")", "{", "return", "nil", "\n", "}", "\n", "ipv6Addrs", ":=", "make", "(", "map", "[", "string", "]", "*", "net", ".", "Interface", ")", "\n", "ifaces", ",", "err", ":=", "vlanInterfaces", "(", "pIface", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "ifaces", "=", "append", "(", "ifaces", ",", "pIface", ")", "\n", "for", "_", ",", "iface", ":=", "range", "ifaces", "{", "out", ",", "err", "=", "ipRunOutput", "(", "\"-6 addr show dev %s scope global\"", ",", "iface", ".", "Name", ")", "\n", "for", "_", ",", "line", ":=", "range", "strings", ".", "Split", "(", "out", ",", "\"\\n\"", ")", "\\n", "\n", "}", "\n", "{", "if", "match", ":=", "ipv6AddrRegexp", ".", "FindStringSubmatch", "(", "line", ")", ";", "match", "!=", "nil", "{", "ipv6Addrs", "[", "match", "[", "1", "]", "]", "=", "iface", "\n", "}", "\n", "}", "\n", "if", "err", ":=", "ifaceFastDown", "(", "pIface", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "for", "addr", ",", "iface", ":=", "range", "ipv6Addrs", "{", "if", "err", ":=", "ipRunIface", "(", "iface", ",", "\"addr add %s dev %s\"", ",", "addr", ",", "iface", ".", "Name", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "}" ]
// ifaceDown sets the interface link state to down and preserves IPv6 addresses // for both the given interface and any associated VLAN interfaces.
[ "ifaceDown", "sets", "the", "interface", "link", "state", "to", "down", "and", "preserves", "IPv6", "addresses", "for", "both", "the", "given", "interface", "and", "any", "associated", "VLAN", "interfaces", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ip.go#L106-L139
train
google/seesaw
ncc/ip.go
ifaceSetMAC
func ifaceSetMAC(iface *net.Interface) error { return ipRunIface(iface, "link set %s address %s", iface.Name, iface.HardwareAddr) }
go
func ifaceSetMAC(iface *net.Interface) error { return ipRunIface(iface, "link set %s address %s", iface.Name, iface.HardwareAddr) }
[ "func", "ifaceSetMAC", "(", "iface", "*", "net", ".", "Interface", ")", "error", "{", "return", "ipRunIface", "(", "iface", ",", "\"link set %s address %s\"", ",", "iface", ".", "Name", ",", "iface", ".", "HardwareAddr", ")", "\n", "}" ]
// ifaceSetMAC sets the interface MAC address.
[ "ifaceSetMAC", "sets", "the", "interface", "MAC", "address", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ip.go#L153-L155
train
google/seesaw
ncc/ip.go
ifaceAddIPAddr
func ifaceAddIPAddr(iface *net.Interface, ip net.IP, mask net.IPMask) error { if ip.To4() != nil { return ifaceAddIPv4Addr(iface, ip, mask) } return ifaceAddIPv6Addr(iface, ip, mask) }
go
func ifaceAddIPAddr(iface *net.Interface, ip net.IP, mask net.IPMask) error { if ip.To4() != nil { return ifaceAddIPv4Addr(iface, ip, mask) } return ifaceAddIPv6Addr(iface, ip, mask) }
[ "func", "ifaceAddIPAddr", "(", "iface", "*", "net", ".", "Interface", ",", "ip", "net", ".", "IP", ",", "mask", "net", ".", "IPMask", ")", "error", "{", "if", "ip", ".", "To4", "(", ")", "!=", "nil", "{", "return", "ifaceAddIPv4Addr", "(", "iface", ",", "ip", ",", "mask", ")", "\n", "}", "\n", "return", "ifaceAddIPv6Addr", "(", "iface", ",", "ip", ",", "mask", ")", "\n", "}" ]
// ifaceAddIPAddr adds the given IP address to the network interface.
[ "ifaceAddIPAddr", "adds", "the", "given", "IP", "address", "to", "the", "network", "interface", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ip.go#L158-L163
train
google/seesaw
ncc/ip.go
ifaceAddIPv4Addr
func ifaceAddIPv4Addr(iface *net.Interface, ip net.IP, mask net.IPMask) error { if ip.To4() == nil { return fmt.Errorf("IP %v is not a valid IPv4 address", ip) } brd := make(net.IP, net.IPv4len) copy(brd, ip.To4()) for i := 0; i < net.IPv4len; i++ { brd[i] |= ^mask[i] } prefixLen, _ := mask.Size() return ipRunIface(iface, "addr add %s/%d brd %s dev %s", ip, prefixLen, brd, iface.Name) }
go
func ifaceAddIPv4Addr(iface *net.Interface, ip net.IP, mask net.IPMask) error { if ip.To4() == nil { return fmt.Errorf("IP %v is not a valid IPv4 address", ip) } brd := make(net.IP, net.IPv4len) copy(brd, ip.To4()) for i := 0; i < net.IPv4len; i++ { brd[i] |= ^mask[i] } prefixLen, _ := mask.Size() return ipRunIface(iface, "addr add %s/%d brd %s dev %s", ip, prefixLen, brd, iface.Name) }
[ "func", "ifaceAddIPv4Addr", "(", "iface", "*", "net", ".", "Interface", ",", "ip", "net", ".", "IP", ",", "mask", "net", ".", "IPMask", ")", "error", "{", "if", "ip", ".", "To4", "(", ")", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"IP %v is not a valid IPv4 address\"", ",", "ip", ")", "\n", "}", "\n", "brd", ":=", "make", "(", "net", ".", "IP", ",", "net", ".", "IPv4len", ")", "\n", "copy", "(", "brd", ",", "ip", ".", "To4", "(", ")", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "net", ".", "IPv4len", ";", "i", "++", "{", "brd", "[", "i", "]", "|=", "^", "mask", "[", "i", "]", "\n", "}", "\n", "prefixLen", ",", "_", ":=", "mask", ".", "Size", "(", ")", "\n", "return", "ipRunIface", "(", "iface", ",", "\"addr add %s/%d brd %s dev %s\"", ",", "ip", ",", "prefixLen", ",", "brd", ",", "iface", ".", "Name", ")", "\n", "}" ]
// ifaceAddIPv4Addr adds the given IPv4 address to the network interface.
[ "ifaceAddIPv4Addr", "adds", "the", "given", "IPv4", "address", "to", "the", "network", "interface", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ip.go#L166-L177
train
google/seesaw
ncc/ip.go
ifaceAddIPv6Addr
func ifaceAddIPv6Addr(iface *net.Interface, ip net.IP, mask net.IPMask) error { prefixLen, _ := mask.Size() return ipRunIface(iface, "addr add %s/%d dev %s", ip, prefixLen, iface.Name) }
go
func ifaceAddIPv6Addr(iface *net.Interface, ip net.IP, mask net.IPMask) error { prefixLen, _ := mask.Size() return ipRunIface(iface, "addr add %s/%d dev %s", ip, prefixLen, iface.Name) }
[ "func", "ifaceAddIPv6Addr", "(", "iface", "*", "net", ".", "Interface", ",", "ip", "net", ".", "IP", ",", "mask", "net", ".", "IPMask", ")", "error", "{", "prefixLen", ",", "_", ":=", "mask", ".", "Size", "(", ")", "\n", "return", "ipRunIface", "(", "iface", ",", "\"addr add %s/%d dev %s\"", ",", "ip", ",", "prefixLen", ",", "iface", ".", "Name", ")", "\n", "}" ]
// ifaceAddIPv6Addr adds the given IPv6 address to the network interface.
[ "ifaceAddIPv6Addr", "adds", "the", "given", "IPv6", "address", "to", "the", "network", "interface", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ip.go#L180-L183
train
google/seesaw
ncc/ip.go
ifaceAddVLAN
func ifaceAddVLAN(iface *net.Interface, vlan *seesaw.VLAN) error { name := fmt.Sprintf("%s.%d", iface.Name, vlan.ID) err := ipRunIface(iface, "link add link %s name %s type vlan id %d", iface.Name, name, vlan.ID) if err != nil { return fmt.Errorf("Failed to create VLAN interface %q: %v", name, err) } vlanIface, err := net.InterfaceByName(name) if err != nil { return fmt.Errorf("Failed to find newly created VLAN interface %q: %v", name, err) } if err := sysctlInitIface(vlanIface.Name); err != nil { return fmt.Errorf("Failed to initialise sysctls for VLAN interface %q: %v", name, err) } if vlan.IPv4Addr != nil { if err := ifaceAddIPv4Addr(vlanIface, vlan.IPv4Addr, vlan.IPv4Mask); err != nil { return fmt.Errorf("Failed to add %v to VLAN interface %q", vlan.IPv4Addr, name) } } if vlan.IPv6Addr != nil { if err := ifaceAddIPv6Addr(vlanIface, vlan.IPv6Addr, vlan.IPv6Mask); err != nil { return fmt.Errorf("Failed to add %v to VLAN interface %q", vlan.IPv6Addr, name) } } if iface.Flags&net.FlagUp == 0 { return nil } return ifaceUp(vlanIface) }
go
func ifaceAddVLAN(iface *net.Interface, vlan *seesaw.VLAN) error { name := fmt.Sprintf("%s.%d", iface.Name, vlan.ID) err := ipRunIface(iface, "link add link %s name %s type vlan id %d", iface.Name, name, vlan.ID) if err != nil { return fmt.Errorf("Failed to create VLAN interface %q: %v", name, err) } vlanIface, err := net.InterfaceByName(name) if err != nil { return fmt.Errorf("Failed to find newly created VLAN interface %q: %v", name, err) } if err := sysctlInitIface(vlanIface.Name); err != nil { return fmt.Errorf("Failed to initialise sysctls for VLAN interface %q: %v", name, err) } if vlan.IPv4Addr != nil { if err := ifaceAddIPv4Addr(vlanIface, vlan.IPv4Addr, vlan.IPv4Mask); err != nil { return fmt.Errorf("Failed to add %v to VLAN interface %q", vlan.IPv4Addr, name) } } if vlan.IPv6Addr != nil { if err := ifaceAddIPv6Addr(vlanIface, vlan.IPv6Addr, vlan.IPv6Mask); err != nil { return fmt.Errorf("Failed to add %v to VLAN interface %q", vlan.IPv6Addr, name) } } if iface.Flags&net.FlagUp == 0 { return nil } return ifaceUp(vlanIface) }
[ "func", "ifaceAddVLAN", "(", "iface", "*", "net", ".", "Interface", ",", "vlan", "*", "seesaw", ".", "VLAN", ")", "error", "{", "name", ":=", "fmt", ".", "Sprintf", "(", "\"%s.%d\"", ",", "iface", ".", "Name", ",", "vlan", ".", "ID", ")", "\n", "err", ":=", "ipRunIface", "(", "iface", ",", "\"link add link %s name %s type vlan id %d\"", ",", "iface", ".", "Name", ",", "name", ",", "vlan", ".", "ID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"Failed to create VLAN interface %q: %v\"", ",", "name", ",", "err", ")", "\n", "}", "\n", "vlanIface", ",", "err", ":=", "net", ".", "InterfaceByName", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"Failed to find newly created VLAN interface %q: %v\"", ",", "name", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "sysctlInitIface", "(", "vlanIface", ".", "Name", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"Failed to initialise sysctls for VLAN interface %q: %v\"", ",", "name", ",", "err", ")", "\n", "}", "\n", "if", "vlan", ".", "IPv4Addr", "!=", "nil", "{", "if", "err", ":=", "ifaceAddIPv4Addr", "(", "vlanIface", ",", "vlan", ".", "IPv4Addr", ",", "vlan", ".", "IPv4Mask", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"Failed to add %v to VLAN interface %q\"", ",", "vlan", ".", "IPv4Addr", ",", "name", ")", "\n", "}", "\n", "}", "\n", "if", "vlan", ".", "IPv6Addr", "!=", "nil", "{", "if", "err", ":=", "ifaceAddIPv6Addr", "(", "vlanIface", ",", "vlan", ".", "IPv6Addr", ",", "vlan", ".", "IPv6Mask", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"Failed to add %v to VLAN interface %q\"", ",", "vlan", ".", "IPv6Addr", ",", "name", ")", "\n", "}", "\n", "}", "\n", "if", "iface", ".", "Flags", "&", "net", ".", "FlagUp", "==", "0", "{", "return", "nil", "\n", "}", "\n", "return", "ifaceUp", "(", "vlanIface", ")", "\n", "}" ]
// ifaceAddVLAN creates a new VLAN interface on the given physical interface.
[ "ifaceAddVLAN", "creates", "a", "new", "VLAN", "interface", "on", "the", "given", "physical", "interface", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ip.go#L197-L228
train
google/seesaw
ncc/ip.go
ifaceDelVLAN
func ifaceDelVLAN(iface *net.Interface, vlan *seesaw.VLAN) error { name := fmt.Sprintf("%s.%d", iface.Name, vlan.ID) vlanIface, err := net.InterfaceByName(name) if err != nil { return fmt.Errorf("Failed to find VLAN interface %q: %v", name, err) } return ipRunIface(vlanIface, "link del dev %s", vlanIface.Name) }
go
func ifaceDelVLAN(iface *net.Interface, vlan *seesaw.VLAN) error { name := fmt.Sprintf("%s.%d", iface.Name, vlan.ID) vlanIface, err := net.InterfaceByName(name) if err != nil { return fmt.Errorf("Failed to find VLAN interface %q: %v", name, err) } return ipRunIface(vlanIface, "link del dev %s", vlanIface.Name) }
[ "func", "ifaceDelVLAN", "(", "iface", "*", "net", ".", "Interface", ",", "vlan", "*", "seesaw", ".", "VLAN", ")", "error", "{", "name", ":=", "fmt", ".", "Sprintf", "(", "\"%s.%d\"", ",", "iface", ".", "Name", ",", "vlan", ".", "ID", ")", "\n", "vlanIface", ",", "err", ":=", "net", ".", "InterfaceByName", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"Failed to find VLAN interface %q: %v\"", ",", "name", ",", "err", ")", "\n", "}", "\n", "return", "ipRunIface", "(", "vlanIface", ",", "\"link del dev %s\"", ",", "vlanIface", ".", "Name", ")", "\n", "}" ]
// ifaceDelVLAN removes a VLAN interface from the given physical interface.
[ "ifaceDelVLAN", "removes", "a", "VLAN", "interface", "from", "the", "given", "physical", "interface", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ip.go#L231-L238
train
google/seesaw
ncc/ip.go
ifaceFlushVLANs
func ifaceFlushVLANs(iface *net.Interface) error { if err := validateInterface(iface); err != nil { return err } vlanIfaces, err := vlanInterfaces(iface) if err != nil { return err } for _, vlanIface := range vlanIfaces { if err := ipRunIface(vlanIface, "link del dev %s", vlanIface.Name); err != nil { return fmt.Errorf("Failed to remove %s from %s: %v", vlanIface.Name, iface.Name, err) } } return nil }
go
func ifaceFlushVLANs(iface *net.Interface) error { if err := validateInterface(iface); err != nil { return err } vlanIfaces, err := vlanInterfaces(iface) if err != nil { return err } for _, vlanIface := range vlanIfaces { if err := ipRunIface(vlanIface, "link del dev %s", vlanIface.Name); err != nil { return fmt.Errorf("Failed to remove %s from %s: %v", vlanIface.Name, iface.Name, err) } } return nil }
[ "func", "ifaceFlushVLANs", "(", "iface", "*", "net", ".", "Interface", ")", "error", "{", "if", "err", ":=", "validateInterface", "(", "iface", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "vlanIfaces", ",", "err", ":=", "vlanInterfaces", "(", "iface", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "for", "_", ",", "vlanIface", ":=", "range", "vlanIfaces", "{", "if", "err", ":=", "ipRunIface", "(", "vlanIface", ",", "\"link del dev %s\"", ",", "vlanIface", ".", "Name", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"Failed to remove %s from %s: %v\"", ",", "vlanIface", ".", "Name", ",", "iface", ".", "Name", ",", "err", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// ifaceFlushVLANs removes all VLAN interfaces from the given physical // interface.
[ "ifaceFlushVLANs", "removes", "all", "VLAN", "interfaces", "from", "the", "given", "physical", "interface", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ip.go#L242-L256
train
google/seesaw
ncc/ip.go
routeDefaultIPv4
func routeDefaultIPv4() (net.IP, error) { out, err := ipRunAFOutput(seesaw.IPv4, "route show default") if err != nil { return nil, err } if dr := routeDefaultIPv4Regexp.FindStringSubmatch(out); dr != nil { return net.ParseIP(dr[1]).To4(), nil } return nil, fmt.Errorf("Default route not found") }
go
func routeDefaultIPv4() (net.IP, error) { out, err := ipRunAFOutput(seesaw.IPv4, "route show default") if err != nil { return nil, err } if dr := routeDefaultIPv4Regexp.FindStringSubmatch(out); dr != nil { return net.ParseIP(dr[1]).To4(), nil } return nil, fmt.Errorf("Default route not found") }
[ "func", "routeDefaultIPv4", "(", ")", "(", "net", ".", "IP", ",", "error", ")", "{", "out", ",", "err", ":=", "ipRunAFOutput", "(", "seesaw", ".", "IPv4", ",", "\"route show default\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "dr", ":=", "routeDefaultIPv4Regexp", ".", "FindStringSubmatch", "(", "out", ")", ";", "dr", "!=", "nil", "{", "return", "net", ".", "ParseIP", "(", "dr", "[", "1", "]", ")", ".", "To4", "(", ")", ",", "nil", "\n", "}", "\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"Default route not found\"", ")", "\n", "}" ]
// routeDefaultIPv4 returns the default route for IPv4 traffic.
[ "routeDefaultIPv4", "returns", "the", "default", "route", "for", "IPv4", "traffic", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ip.go#L259-L268
train
google/seesaw
ncc/ip.go
removeRoutes
func removeRoutes(table string, vip net.IP) error { af := seesaw.IPv6 if vip.To4() != nil { af = seesaw.IPv4 } return ipRunAF(af, "route flush table %s %s", table, vip) }
go
func removeRoutes(table string, vip net.IP) error { af := seesaw.IPv6 if vip.To4() != nil { af = seesaw.IPv4 } return ipRunAF(af, "route flush table %s %s", table, vip) }
[ "func", "removeRoutes", "(", "table", "string", ",", "vip", "net", ".", "IP", ")", "error", "{", "af", ":=", "seesaw", ".", "IPv6", "\n", "if", "vip", ".", "To4", "(", ")", "!=", "nil", "{", "af", "=", "seesaw", ".", "IPv4", "\n", "}", "\n", "return", "ipRunAF", "(", "af", ",", "\"route flush table %s %s\"", ",", "table", ",", "vip", ")", "\n", "}" ]
// removeRoutes deletes the routing table entries for a VIP, from the specified // table.
[ "removeRoutes", "deletes", "the", "routing", "table", "entries", "for", "a", "VIP", "from", "the", "specified", "table", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ip.go#L272-L278
train
google/seesaw
ncc/ip.go
routeLocal
func routeLocal(iface *net.Interface, vip net.IP, node seesaw.Host) error { af := seesaw.IPv6 src := node.IPv6Addr if vip.To4() != nil { af = seesaw.IPv4 src = node.IPv4Addr } if err := removeLocalRoutes(vip); err != nil { return err } return ipRunAF(af, "route add table local local %s dev %s src %s", vip, iface.Name, src) }
go
func routeLocal(iface *net.Interface, vip net.IP, node seesaw.Host) error { af := seesaw.IPv6 src := node.IPv6Addr if vip.To4() != nil { af = seesaw.IPv4 src = node.IPv4Addr } if err := removeLocalRoutes(vip); err != nil { return err } return ipRunAF(af, "route add table local local %s dev %s src %s", vip, iface.Name, src) }
[ "func", "routeLocal", "(", "iface", "*", "net", ".", "Interface", ",", "vip", "net", ".", "IP", ",", "node", "seesaw", ".", "Host", ")", "error", "{", "af", ":=", "seesaw", ".", "IPv6", "\n", "src", ":=", "node", ".", "IPv6Addr", "\n", "if", "vip", ".", "To4", "(", ")", "!=", "nil", "{", "af", "=", "seesaw", ".", "IPv4", "\n", "src", "=", "node", ".", "IPv4Addr", "\n", "}", "\n", "if", "err", ":=", "removeLocalRoutes", "(", "vip", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "ipRunAF", "(", "af", ",", "\"route add table local local %s dev %s src %s\"", ",", "vip", ",", "iface", ".", "Name", ",", "src", ")", "\n", "}" ]
// routeLocal removes all routes in the local routing table for the given VIP // and adds new routes with the correct source address.
[ "routeLocal", "removes", "all", "routes", "in", "the", "local", "routing", "table", "for", "the", "given", "VIP", "and", "adds", "new", "routes", "with", "the", "correct", "source", "address", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ip.go#L292-L303
train
google/seesaw
ncc/ip.go
RouteDefaultIPv4
func (ncc *SeesawNCC) RouteDefaultIPv4(unused int, gateway *net.IP) error { ip, err := routeDefaultIPv4() if err != nil { return err } if gateway != nil { *gateway = make(net.IP, len(ip)) copy(*gateway, ip) } return nil }
go
func (ncc *SeesawNCC) RouteDefaultIPv4(unused int, gateway *net.IP) error { ip, err := routeDefaultIPv4() if err != nil { return err } if gateway != nil { *gateway = make(net.IP, len(ip)) copy(*gateway, ip) } return nil }
[ "func", "(", "ncc", "*", "SeesawNCC", ")", "RouteDefaultIPv4", "(", "unused", "int", ",", "gateway", "*", "net", ".", "IP", ")", "error", "{", "ip", ",", "err", ":=", "routeDefaultIPv4", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "gateway", "!=", "nil", "{", "*", "gateway", "=", "make", "(", "net", ".", "IP", ",", "len", "(", "ip", ")", ")", "\n", "copy", "(", "*", "gateway", ",", "ip", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// RouteDefaultIPv4 returns the default route for IPv4 traffic.
[ "RouteDefaultIPv4", "returns", "the", "default", "route", "for", "IPv4", "traffic", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ip.go#L306-L316
train
google/seesaw
ncc/lb.go
addClusterVIP
func addClusterVIP(iface *ncctypes.LBInterface, netIface, nodeIface *net.Interface, clusterVIP net.IP) error { nodeIP := iface.Node.IPv4Addr family := seesaw.IPv4 if clusterVIP.To4() == nil { nodeIP = iface.Node.IPv6Addr family = seesaw.IPv6 } if nodeIP == nil { return fmt.Errorf("Node does not have an %s address", family) } log.Infof("Adding %s cluster VIP %s on %s", family, clusterVIP, iface.Name) // Determine network for the node IP and ensure that the cluster VIP is // contained within this network. nodeNet, err := findNetwork(nodeIface, nodeIP) if err != nil { return fmt.Errorf("Failed to get node network: %v", err) } if !nodeNet.Contains(clusterVIP) { return fmt.Errorf("Node network %s does not contain cluster VIP %s", nodeNet, clusterVIP) } // Set up routing policy for IPv4. These rules and the associated routes // added in LBInterfaceUp tell the seesaw to: // 1) Respond to ARP requests for the seesaw VIP // 2) Send seesaw VIP reply traffic out eth1 // // For IPv6, policy routing won't work on physical machines until // b/10061534 is resolved. VIP reply traffic will go out eth0 which is fine, // and neighbor discovery for the seesaw VIP works fine without policy routing // anyway. // // TODO(angusc): Figure out how whether we can get rid of this. if family == seesaw.IPv4 { ipRunAF(family, "rule del to %s", clusterVIP) ipRunAF(family, "rule del from %s", clusterVIP) if err := ipRunAF(family, "rule add from all to %s lookup %d", clusterVIP, iface.RoutingTableID); err != nil { return fmt.Errorf("Failed to set up routing policy: %v", err) } if err := ipRunAF(family, "rule add from %s lookup %d", clusterVIP, iface.RoutingTableID); err != nil { return fmt.Errorf("Failed to set up routing policy: %v", err) } } // Add cluster VIP to interface. if err := ifaceAddIPAddr(netIface, clusterVIP, nodeNet.Mask); err != nil { return fmt.Errorf("Failed to add cluster VIP to interface: %v", err) } return nil }
go
func addClusterVIP(iface *ncctypes.LBInterface, netIface, nodeIface *net.Interface, clusterVIP net.IP) error { nodeIP := iface.Node.IPv4Addr family := seesaw.IPv4 if clusterVIP.To4() == nil { nodeIP = iface.Node.IPv6Addr family = seesaw.IPv6 } if nodeIP == nil { return fmt.Errorf("Node does not have an %s address", family) } log.Infof("Adding %s cluster VIP %s on %s", family, clusterVIP, iface.Name) // Determine network for the node IP and ensure that the cluster VIP is // contained within this network. nodeNet, err := findNetwork(nodeIface, nodeIP) if err != nil { return fmt.Errorf("Failed to get node network: %v", err) } if !nodeNet.Contains(clusterVIP) { return fmt.Errorf("Node network %s does not contain cluster VIP %s", nodeNet, clusterVIP) } // Set up routing policy for IPv4. These rules and the associated routes // added in LBInterfaceUp tell the seesaw to: // 1) Respond to ARP requests for the seesaw VIP // 2) Send seesaw VIP reply traffic out eth1 // // For IPv6, policy routing won't work on physical machines until // b/10061534 is resolved. VIP reply traffic will go out eth0 which is fine, // and neighbor discovery for the seesaw VIP works fine without policy routing // anyway. // // TODO(angusc): Figure out how whether we can get rid of this. if family == seesaw.IPv4 { ipRunAF(family, "rule del to %s", clusterVIP) ipRunAF(family, "rule del from %s", clusterVIP) if err := ipRunAF(family, "rule add from all to %s lookup %d", clusterVIP, iface.RoutingTableID); err != nil { return fmt.Errorf("Failed to set up routing policy: %v", err) } if err := ipRunAF(family, "rule add from %s lookup %d", clusterVIP, iface.RoutingTableID); err != nil { return fmt.Errorf("Failed to set up routing policy: %v", err) } } // Add cluster VIP to interface. if err := ifaceAddIPAddr(netIface, clusterVIP, nodeNet.Mask); err != nil { return fmt.Errorf("Failed to add cluster VIP to interface: %v", err) } return nil }
[ "func", "addClusterVIP", "(", "iface", "*", "ncctypes", ".", "LBInterface", ",", "netIface", ",", "nodeIface", "*", "net", ".", "Interface", ",", "clusterVIP", "net", ".", "IP", ")", "error", "{", "nodeIP", ":=", "iface", ".", "Node", ".", "IPv4Addr", "\n", "family", ":=", "seesaw", ".", "IPv4", "\n", "if", "clusterVIP", ".", "To4", "(", ")", "==", "nil", "{", "nodeIP", "=", "iface", ".", "Node", ".", "IPv6Addr", "\n", "family", "=", "seesaw", ".", "IPv6", "\n", "}", "\n", "if", "nodeIP", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"Node does not have an %s address\"", ",", "family", ")", "\n", "}", "\n", "log", ".", "Infof", "(", "\"Adding %s cluster VIP %s on %s\"", ",", "family", ",", "clusterVIP", ",", "iface", ".", "Name", ")", "\n", "nodeNet", ",", "err", ":=", "findNetwork", "(", "nodeIface", ",", "nodeIP", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"Failed to get node network: %v\"", ",", "err", ")", "\n", "}", "\n", "if", "!", "nodeNet", ".", "Contains", "(", "clusterVIP", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"Node network %s does not contain cluster VIP %s\"", ",", "nodeNet", ",", "clusterVIP", ")", "\n", "}", "\n", "if", "family", "==", "seesaw", ".", "IPv4", "{", "ipRunAF", "(", "family", ",", "\"rule del to %s\"", ",", "clusterVIP", ")", "\n", "ipRunAF", "(", "family", ",", "\"rule del from %s\"", ",", "clusterVIP", ")", "\n", "if", "err", ":=", "ipRunAF", "(", "family", ",", "\"rule add from all to %s lookup %d\"", ",", "clusterVIP", ",", "iface", ".", "RoutingTableID", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"Failed to set up routing policy: %v\"", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "ipRunAF", "(", "family", ",", "\"rule add from %s lookup %d\"", ",", "clusterVIP", ",", "iface", ".", "RoutingTableID", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"Failed to set up routing policy: %v\"", ",", "err", ")", "\n", "}", "\n", "}", "\n", "if", "err", ":=", "ifaceAddIPAddr", "(", "netIface", ",", "clusterVIP", ",", "nodeNet", ".", "Mask", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"Failed to add cluster VIP to interface: %v\"", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// addClusterVIP adds a cluster VIP to the load balancing interface and // performs additional network configuration.
[ "addClusterVIP", "adds", "a", "cluster", "VIP", "to", "the", "load", "balancing", "interface", "and", "performs", "additional", "network", "configuration", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/lb.go#L120-L171
train
google/seesaw
ncc/lb.go
LBInterfaceDown
func (ncc *SeesawNCC) LBInterfaceDown(iface *ncctypes.LBInterface, out *int) error { netIface, err := iface.Interface() if err != nil { return err } log.Infof("Bringing down LB interface %s", netIface.Name) return ifaceDown(netIface) }
go
func (ncc *SeesawNCC) LBInterfaceDown(iface *ncctypes.LBInterface, out *int) error { netIface, err := iface.Interface() if err != nil { return err } log.Infof("Bringing down LB interface %s", netIface.Name) return ifaceDown(netIface) }
[ "func", "(", "ncc", "*", "SeesawNCC", ")", "LBInterfaceDown", "(", "iface", "*", "ncctypes", ".", "LBInterface", ",", "out", "*", "int", ")", "error", "{", "netIface", ",", "err", ":=", "iface", ".", "Interface", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "log", ".", "Infof", "(", "\"Bringing down LB interface %s\"", ",", "netIface", ".", "Name", ")", "\n", "return", "ifaceDown", "(", "netIface", ")", "\n", "}" ]
// LBInterfaceDown brings the load balancing interface down.
[ "LBInterfaceDown", "brings", "the", "load", "balancing", "interface", "down", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/lb.go#L174-L181
train
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("Failed to get node interface: %v", err) } nodeNet, err := findNetwork(nodeIface, iface.Node.IPv4Addr) if err != nil { return fmt.Errorf("Failed to get node network: %v", err) } log.Infof("Bringing up LB interface %s on %s", nodeNet, iface.Name) if !nodeNet.Contains(iface.ClusterVIP.IPv4Addr) { return fmt.Errorf("Node network %s does not contain cluster VIP %s", nodeNet, iface.ClusterVIP.IPv4Addr) } gateway, err := routeDefaultIPv4() if err != nil { return fmt.Errorf("Failed to get IPv4 default route: %v", err) } if err := ifaceUp(netIface); err != nil { return fmt.Errorf("Failed to bring interface up: %v", err) } // Configure routing. if err := ipRunIface(netIface, "route add %s dev %s table %d", nodeNet, iface.Name, iface.RoutingTableID); err != nil { return fmt.Errorf("Failed to configure routing: %v", err) } if err := ipRunIface(netIface, "route add 0/0 via %s dev %s table %d", gateway, iface.Name, iface.RoutingTableID); err != nil { return fmt.Errorf("Failed to configure routing: %v", err) } return nil }
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("Failed to get node interface: %v", err) } nodeNet, err := findNetwork(nodeIface, iface.Node.IPv4Addr) if err != nil { return fmt.Errorf("Failed to get node network: %v", err) } log.Infof("Bringing up LB interface %s on %s", nodeNet, iface.Name) if !nodeNet.Contains(iface.ClusterVIP.IPv4Addr) { return fmt.Errorf("Node network %s does not contain cluster VIP %s", nodeNet, iface.ClusterVIP.IPv4Addr) } gateway, err := routeDefaultIPv4() if err != nil { return fmt.Errorf("Failed to get IPv4 default route: %v", err) } if err := ifaceUp(netIface); err != nil { return fmt.Errorf("Failed to bring interface up: %v", err) } // Configure routing. if err := ipRunIface(netIface, "route add %s dev %s table %d", nodeNet, iface.Name, iface.RoutingTableID); err != nil { return fmt.Errorf("Failed to configure routing: %v", err) } if err := ipRunIface(netIface, "route add 0/0 via %s dev %s table %d", gateway, iface.Name, iface.RoutingTableID); err != nil { return fmt.Errorf("Failed to configure routing: %v", err) } return nil }
[ "func", "(", "ncc", "*", "SeesawNCC", ")", "LBInterfaceUp", "(", "iface", "*", "ncctypes", ".", "LBInterface", ",", "out", "*", "int", ")", "error", "{", "netIface", ",", "err", ":=", "iface", ".", "Interface", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "nodeIface", ",", "err", ":=", "net", ".", "InterfaceByName", "(", "iface", ".", "NodeInterface", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"Failed to get node interface: %v\"", ",", "err", ")", "\n", "}", "\n", "nodeNet", ",", "err", ":=", "findNetwork", "(", "nodeIface", ",", "iface", ".", "Node", ".", "IPv4Addr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"Failed to get node network: %v\"", ",", "err", ")", "\n", "}", "\n", "log", ".", "Infof", "(", "\"Bringing up LB interface %s on %s\"", ",", "nodeNet", ",", "iface", ".", "Name", ")", "\n", "if", "!", "nodeNet", ".", "Contains", "(", "iface", ".", "ClusterVIP", ".", "IPv4Addr", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"Node network %s does not contain cluster VIP %s\"", ",", "nodeNet", ",", "iface", ".", "ClusterVIP", ".", "IPv4Addr", ")", "\n", "}", "\n", "gateway", ",", "err", ":=", "routeDefaultIPv4", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"Failed to get IPv4 default route: %v\"", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "ifaceUp", "(", "netIface", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"Failed to bring interface up: %v\"", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "ipRunIface", "(", "netIface", ",", "\"route add %s dev %s table %d\"", ",", "nodeNet", ",", "iface", ".", "Name", ",", "iface", ".", "RoutingTableID", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"Failed to configure routing: %v\"", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "ipRunIface", "(", "netIface", ",", "\"route add 0/0 via %s dev %s table %d\"", ",", "gateway", ",", "iface", ".", "Name", ",", "iface", ".", "RoutingTableID", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"Failed to configure routing: %v\"", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// 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", ".", "Iface", ".", "ClusterVIP", ",", "lbVserver", ".", "AF", ")", "\n", "}" ]
// 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", ".", "Iface", ".", "ClusterVIP", ",", "lbVserver", ".", "AF", ")", "\n", "}" ]
// 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("Failed to select interface and network for %v: %v", vip.VIP, err) } log.Infof("Adding VIP %s to %s", vip.IP.IP(), iface.Name) if err := ifaceAddIPAddr(iface, vip.IP.IP(), network.Mask); err != nil { return err } return routeLocal(iface, vip.IP.IP(), vip.Iface.Node) case seesaw.AnycastVIP, seesaw.DedicatedVIP: dummyIface, err := net.InterfaceByName(vip.Iface.DummyInterface) if err != nil { return fmt.Errorf("Failed to find dummy interface: %v", err) } prefixLen := net.IPv6len * 8 if vip.IP.IP().To4() != nil { prefixLen = net.IPv4len * 8 } mask := net.CIDRMask(prefixLen, prefixLen) log.Infof("Adding VIP %s to %s", vip.IP.IP(), dummyIface.Name) if err := ifaceAddIPAddr(dummyIface, vip.IP.IP(), mask); err != nil { return err } return routeLocal(dummyIface, vip.IP.IP(), vip.Iface.Node) default: return fmt.Errorf("Unknown VIPType for %v: %v", vip.VIP, vip.Type) } }
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("Failed to select interface and network for %v: %v", vip.VIP, err) } log.Infof("Adding VIP %s to %s", vip.IP.IP(), iface.Name) if err := ifaceAddIPAddr(iface, vip.IP.IP(), network.Mask); err != nil { return err } return routeLocal(iface, vip.IP.IP(), vip.Iface.Node) case seesaw.AnycastVIP, seesaw.DedicatedVIP: dummyIface, err := net.InterfaceByName(vip.Iface.DummyInterface) if err != nil { return fmt.Errorf("Failed to find dummy interface: %v", err) } prefixLen := net.IPv6len * 8 if vip.IP.IP().To4() != nil { prefixLen = net.IPv4len * 8 } mask := net.CIDRMask(prefixLen, prefixLen) log.Infof("Adding VIP %s to %s", vip.IP.IP(), dummyIface.Name) if err := ifaceAddIPAddr(dummyIface, vip.IP.IP(), mask); err != nil { return err } return routeLocal(dummyIface, vip.IP.IP(), vip.Iface.Node) default: return fmt.Errorf("Unknown VIPType for %v: %v", vip.VIP, vip.Type) } }
[ "func", "(", "ncc", "*", "SeesawNCC", ")", "LBInterfaceAddVIP", "(", "vip", "*", "ncctypes", ".", "LBInterfaceVIP", ",", "out", "*", "int", ")", "error", "{", "switch", "vip", ".", "Type", "{", "case", "seesaw", ".", "UnicastVIP", ":", "netIface", ",", "err", ":=", "vip", ".", "Iface", ".", "Interface", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "iface", ",", "network", ",", "err", ":=", "selectInterfaceNetwork", "(", "netIface", ",", "vip", ".", "IP", ".", "IP", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"Failed to select interface and network for %v: %v\"", ",", "vip", ".", "VIP", ",", "err", ")", "\n", "}", "\n", "log", ".", "Infof", "(", "\"Adding VIP %s to %s\"", ",", "vip", ".", "IP", ".", "IP", "(", ")", ",", "iface", ".", "Name", ")", "\n", "if", "err", ":=", "ifaceAddIPAddr", "(", "iface", ",", "vip", ".", "IP", ".", "IP", "(", ")", ",", "network", ".", "Mask", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "routeLocal", "(", "iface", ",", "vip", ".", "IP", ".", "IP", "(", ")", ",", "vip", ".", "Iface", ".", "Node", ")", "\n", "case", "seesaw", ".", "AnycastVIP", ",", "seesaw", ".", "DedicatedVIP", ":", "dummyIface", ",", "err", ":=", "net", ".", "InterfaceByName", "(", "vip", ".", "Iface", ".", "DummyInterface", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"Failed to find dummy interface: %v\"", ",", "err", ")", "\n", "}", "\n", "prefixLen", ":=", "net", ".", "IPv6len", "*", "8", "\n", "if", "vip", ".", "IP", ".", "IP", "(", ")", ".", "To4", "(", ")", "!=", "nil", "{", "prefixLen", "=", "net", ".", "IPv4len", "*", "8", "\n", "}", "\n", "mask", ":=", "net", ".", "CIDRMask", "(", "prefixLen", ",", "prefixLen", ")", "\n", "log", ".", "Infof", "(", "\"Adding VIP %s to %s\"", ",", "vip", ".", "IP", ".", "IP", "(", ")", ",", "dummyIface", ".", "Name", ")", "\n", "if", "err", ":=", "ifaceAddIPAddr", "(", "dummyIface", ",", "vip", ".", "IP", ".", "IP", "(", ")", ",", "mask", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "routeLocal", "(", "dummyIface", ",", "vip", ".", "IP", ".", "IP", "(", ")", ",", "vip", ".", "Iface", ".", "Node", ")", "\n", "default", ":", "return", "fmt", ".", "Errorf", "(", "\"Unknown VIPType for %v: %v\"", ",", "vip", ".", "VIP", ",", "vip", ".", "Type", ")", "\n", "}", "\n", "}" ]
// 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("Failed to find interface and network for %v: %v", vip.VIP, err) } log.Infof("Removing VIP %s from %s", vip.IP.IP(), iface.Name) if err := ifaceDelIPAddr(iface, vip.IP.IP(), network.Mask); err != nil { return fmt.Errorf("Failed to delete VIP %s: %v", vip.VIP, err) } if err := removeLocalRoutes(vip.IP.IP()); err != nil { log.Infof("Failed to remove local routes for VIP %s: %v", vip.VIP, err) } if err := removeMainRoutes(vip.VIP.IP.IP()); err != nil { log.Infof("Failed to remove main routes for VIP %s: %v", vip.VIP, err) } return nil case seesaw.AnycastVIP, seesaw.DedicatedVIP: dummyIface, err := net.InterfaceByName(vip.Iface.DummyInterface) if err != nil { return fmt.Errorf("Failed to find dummy interface: %v", err) } prefixLen := net.IPv6len * 8 if vip.IP.IP().To4() != nil { prefixLen = net.IPv4len * 8 } mask := net.CIDRMask(prefixLen, prefixLen) log.Infof("Removing VIP %s from %s", vip.IP.IP(), dummyIface.Name) if err = ifaceDelIPAddr(dummyIface, vip.IP.IP(), mask); err != nil { return fmt.Errorf("Failed to delete VIP %s: %v", vip.VIP, err) } // Workaround for kernel bug(?). The route should have been removed when // address was removed, but this doesn't always happen. An error is // non-fatal since it probably means the route doesn't exist. if err := removeLocalRoutes(vip.VIP.IP.IP()); err != nil { log.Infof("Failed to remove local routes for VIP %s: %v", vip.VIP, err) } if err := removeMainRoutes(vip.VIP.IP.IP()); err != nil { log.Infof("Failed to remove main routes for VIP %s: %v", vip.VIP, err) } return nil default: return fmt.Errorf("Unknown VIPType for %v: %v", vip.VIP, vip.VIP.Type) } }
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("Failed to find interface and network for %v: %v", vip.VIP, err) } log.Infof("Removing VIP %s from %s", vip.IP.IP(), iface.Name) if err := ifaceDelIPAddr(iface, vip.IP.IP(), network.Mask); err != nil { return fmt.Errorf("Failed to delete VIP %s: %v", vip.VIP, err) } if err := removeLocalRoutes(vip.IP.IP()); err != nil { log.Infof("Failed to remove local routes for VIP %s: %v", vip.VIP, err) } if err := removeMainRoutes(vip.VIP.IP.IP()); err != nil { log.Infof("Failed to remove main routes for VIP %s: %v", vip.VIP, err) } return nil case seesaw.AnycastVIP, seesaw.DedicatedVIP: dummyIface, err := net.InterfaceByName(vip.Iface.DummyInterface) if err != nil { return fmt.Errorf("Failed to find dummy interface: %v", err) } prefixLen := net.IPv6len * 8 if vip.IP.IP().To4() != nil { prefixLen = net.IPv4len * 8 } mask := net.CIDRMask(prefixLen, prefixLen) log.Infof("Removing VIP %s from %s", vip.IP.IP(), dummyIface.Name) if err = ifaceDelIPAddr(dummyIface, vip.IP.IP(), mask); err != nil { return fmt.Errorf("Failed to delete VIP %s: %v", vip.VIP, err) } // Workaround for kernel bug(?). The route should have been removed when // address was removed, but this doesn't always happen. An error is // non-fatal since it probably means the route doesn't exist. if err := removeLocalRoutes(vip.VIP.IP.IP()); err != nil { log.Infof("Failed to remove local routes for VIP %s: %v", vip.VIP, err) } if err := removeMainRoutes(vip.VIP.IP.IP()); err != nil { log.Infof("Failed to remove main routes for VIP %s: %v", vip.VIP, err) } return nil default: return fmt.Errorf("Unknown VIPType for %v: %v", vip.VIP, vip.VIP.Type) } }
[ "func", "(", "ncc", "*", "SeesawNCC", ")", "LBInterfaceDeleteVIP", "(", "vip", "*", "ncctypes", ".", "LBInterfaceVIP", ",", "out", "*", "int", ")", "error", "{", "switch", "vip", ".", "Type", "{", "case", "seesaw", ".", "UnicastVIP", ":", "netIface", ",", "err", ":=", "vip", ".", "Iface", ".", "Interface", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "iface", ",", "network", ",", "err", ":=", "findInterfaceNetwork", "(", "netIface", ",", "vip", ".", "IP", ".", "IP", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"Failed to find interface and network for %v: %v\"", ",", "vip", ".", "VIP", ",", "err", ")", "\n", "}", "\n", "log", ".", "Infof", "(", "\"Removing VIP %s from %s\"", ",", "vip", ".", "IP", ".", "IP", "(", ")", ",", "iface", ".", "Name", ")", "\n", "if", "err", ":=", "ifaceDelIPAddr", "(", "iface", ",", "vip", ".", "IP", ".", "IP", "(", ")", ",", "network", ".", "Mask", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"Failed to delete VIP %s: %v\"", ",", "vip", ".", "VIP", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "removeLocalRoutes", "(", "vip", ".", "IP", ".", "IP", "(", ")", ")", ";", "err", "!=", "nil", "{", "log", ".", "Infof", "(", "\"Failed to remove local routes for VIP %s: %v\"", ",", "vip", ".", "VIP", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "removeMainRoutes", "(", "vip", ".", "VIP", ".", "IP", ".", "IP", "(", ")", ")", ";", "err", "!=", "nil", "{", "log", ".", "Infof", "(", "\"Failed to remove main routes for VIP %s: %v\"", ",", "vip", ".", "VIP", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "case", "seesaw", ".", "AnycastVIP", ",", "seesaw", ".", "DedicatedVIP", ":", "dummyIface", ",", "err", ":=", "net", ".", "InterfaceByName", "(", "vip", ".", "Iface", ".", "DummyInterface", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"Failed to find dummy interface: %v\"", ",", "err", ")", "\n", "}", "\n", "prefixLen", ":=", "net", ".", "IPv6len", "*", "8", "\n", "if", "vip", ".", "IP", ".", "IP", "(", ")", ".", "To4", "(", ")", "!=", "nil", "{", "prefixLen", "=", "net", ".", "IPv4len", "*", "8", "\n", "}", "\n", "mask", ":=", "net", ".", "CIDRMask", "(", "prefixLen", ",", "prefixLen", ")", "\n", "log", ".", "Infof", "(", "\"Removing VIP %s from %s\"", ",", "vip", ".", "IP", ".", "IP", "(", ")", ",", "dummyIface", ".", "Name", ")", "\n", "if", "err", "=", "ifaceDelIPAddr", "(", "dummyIface", ",", "vip", ".", "IP", ".", "IP", "(", ")", ",", "mask", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"Failed to delete VIP %s: %v\"", ",", "vip", ".", "VIP", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "removeLocalRoutes", "(", "vip", ".", "VIP", ".", "IP", ".", "IP", "(", ")", ")", ";", "err", "!=", "nil", "{", "log", ".", "Infof", "(", "\"Failed to remove local routes for VIP %s: %v\"", ",", "vip", ".", "VIP", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "removeMainRoutes", "(", "vip", ".", "VIP", ".", "IP", ".", "IP", "(", ")", ")", ";", "err", "!=", "nil", "{", "log", ".", "Infof", "(", "\"Failed to remove main routes for VIP %s: %v\"", ",", "vip", ".", "VIP", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "default", ":", "return", "fmt", ".", "Errorf", "(", "\"Unknown VIPType for %v: %v\"", ",", "vip", ".", "VIP", ",", "vip", ".", "VIP", ".", "Type", ")", "\n", "}", "\n", "}" ]
// 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", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "ifaceAddVLAN", "(", "netIface", ",", "vlan", ".", "VLAN", ")", "\n", "}" ]
// 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", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "ifaceDelVLAN", "(", "netIface", ",", "vlan", ".", "VLAN", ")", "\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) { ifaces = append(ifaces, &allIfaces[i]) } } return ifaces, nil }
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) { ifaces = append(ifaces, &allIfaces[i]) } } return ifaces, nil }
[ "func", "vlanInterfaces", "(", "pIface", "*", "net", ".", "Interface", ")", "(", "[", "]", "*", "net", ".", "Interface", ",", "error", ")", "{", "allIfaces", ",", "err", ":=", "net", ".", "Interfaces", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "ifaces", ":=", "make", "(", "[", "]", "*", "net", ".", "Interface", ",", "0", ",", "len", "(", "allIfaces", ")", ")", "\n", "prefix", ":=", "fmt", ".", "Sprintf", "(", "\"%s.\"", ",", "pIface", ".", "Name", ")", "\n", "for", "i", ",", "iface", ":=", "range", "allIfaces", "{", "if", "strings", ".", "HasPrefix", "(", "iface", ".", "Name", ",", "prefix", ")", "{", "ifaces", "=", "append", "(", "ifaces", ",", "&", "allIfaces", "[", "i", "]", ")", "\n", "}", "\n", "}", "\n", "return", "ifaces", ",", "nil", "\n", "}" ]
// 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, network, nil } } return nil, nil, fmt.Errorf("Failed to find IP %v on any interface", ip) }
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, network, nil } } return nil, nil, fmt.Errorf("Failed to find IP %v on any interface", ip) }
[ "func", "findInterfaceNetwork", "(", "pIface", "*", "net", ".", "Interface", ",", "ip", "net", ".", "IP", ")", "(", "*", "net", ".", "Interface", ",", "*", "net", ".", "IPNet", ",", "error", ")", "{", "ifaces", ",", "err", ":=", "vlanInterfaces", "(", "pIface", ")", "\n", "ifaces", "=", "append", "(", "ifaces", ",", "pIface", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n", "for", "_", ",", "iface", ":=", "range", "ifaces", "{", "if", "network", ",", "_", ":=", "findNetwork", "(", "iface", ",", "ip", ")", ";", "network", "!=", "nil", "{", "return", "iface", ",", "network", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "nil", ",", "nil", ",", "fmt", ".", "Errorf", "(", "\"Failed to find IP %v on any interface\"", ",", "ip", ")", "\n", "}" ]
// 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", "error", "is", "returned", "." ]
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 != nil { return nil, fmt.Errorf("Failed to parse interface address %q - %v: %v", iface.Name, ipStr, err) } if ipAddr.Equal(ip) { return ipNet, nil } } return nil, fmt.Errorf("Failed to find IP %v on interface %q", ip, iface.Name) }
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 != nil { return nil, fmt.Errorf("Failed to parse interface address %q - %v: %v", iface.Name, ipStr, err) } if ipAddr.Equal(ip) { return ipNet, nil } } return nil, fmt.Errorf("Failed to find IP %v on interface %q", ip, iface.Name) }
[ "func", "findNetwork", "(", "iface", "*", "net", ".", "Interface", ",", "ip", "net", ".", "IP", ")", "(", "*", "net", ".", "IPNet", ",", "error", ")", "{", "addrs", ",", "err", ":=", "iface", ".", "Addrs", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"Failed to get addresses for interface %q: %v\"", ",", "iface", ".", "Name", ",", "err", ")", "\n", "}", "\n", "for", "_", ",", "addr", ":=", "range", "addrs", "{", "ipStr", ":=", "addr", ".", "String", "(", ")", "\n", "ipAddr", ",", "ipNet", ",", "err", ":=", "net", ".", "ParseCIDR", "(", "ipStr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"Failed to parse interface address %q - %v: %v\"", ",", "iface", ".", "Name", ",", "ipStr", ",", "err", ")", "\n", "}", "\n", "if", "ipAddr", ".", "Equal", "(", "ip", ")", "{", "return", "ipNet", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"Failed to find IP %v on interface %q\"", ",", "ip", ",", "iface", ".", "Name", ")", "\n", "}" ]
// 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 bool, 1), stopped: make(chan bool, 1), termTimeout: 5 * time.Second, } }
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 bool, 1), stopped: make(chan bool, 1), termTimeout: 5 * time.Second, } }
[ "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", "bool", ",", "1", ")", ",", "stopped", ":", "make", "(", "chan", "bool", ",", "1", ")", ",", "termTimeout", ":", "5", "*", "time", ".", "Second", ",", "}", "\n", "}" ]
// 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", "(", "\"Invalid priority %d - must be between -20 and 19\"", ",", "priority", ")", "\n", "}", "\n", "svc", ".", "priority", "=", "priority", "\n", "return", "nil", "\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", ",", "err", ":=", "strconv", ".", "Atoi", "(", "u", ".", "Uid", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "gid", ",", "err", ":=", "strconv", ".", "Atoi", "(", "u", ".", "Gid", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "svc", ".", "uid", "=", "uint32", "(", "uid", ")", "\n", "svc", ".", "gid", "=", "uint32", "(", "gid", ")", "\n", "return", "nil", "\n", "}" ]
// 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 { delay := time.Duration(svc.failures) * restartBackoff if delay > restartBackoffMax { delay = restartBackoffMax } log.Infof("Service %s has failed %d times - delaying %s before restart", svc.name, svc.failures, delay) select { case <-time.After(delay): case <-svc.shutdown: goto done } } svc.restarts++ svc.lastRestart = time.Now() svc.runOnce() select { case <-time.After(restartDelay): case <-svc.shutdown: goto done } } done: svc.done <- true }
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 { delay := time.Duration(svc.failures) * restartBackoff if delay > restartBackoffMax { delay = restartBackoffMax } log.Infof("Service %s has failed %d times - delaying %s before restart", svc.name, svc.failures, delay) select { case <-time.After(delay): case <-svc.shutdown: goto done } } svc.restarts++ svc.lastRestart = time.Now() svc.runOnce() select { case <-time.After(restartDelay): case <-svc.shutdown: goto done } } done: svc.done <- true }
[ "func", "(", "svc", "*", "Service", ")", "run", "(", ")", "{", "for", "_", ",", "dep", ":=", "range", "svc", ".", "dependencies", "{", "log", ".", "Infof", "(", "\"Service %s waiting for %s to start\"", ",", "svc", ".", "name", ",", "dep", ".", "name", ")", "\n", "select", "{", "case", "started", ":=", "<-", "dep", ".", "started", ":", "dep", ".", "started", "<-", "started", "\n", "case", "<-", "svc", ".", "shutdown", ":", "goto", "done", "\n", "}", "\n", "}", "\n", "for", "{", "if", "svc", ".", "failures", ">", "0", "{", "delay", ":=", "time", ".", "Duration", "(", "svc", ".", "failures", ")", "*", "restartBackoff", "\n", "if", "delay", ">", "restartBackoffMax", "{", "delay", "=", "restartBackoffMax", "\n", "}", "\n", "log", ".", "Infof", "(", "\"Service %s has failed %d times - delaying %s before restart\"", ",", "svc", ".", "name", ",", "svc", ".", "failures", ",", "delay", ")", "\n", "select", "{", "case", "<-", "time", ".", "After", "(", "delay", ")", ":", "case", "<-", "svc", ".", "shutdown", ":", "goto", "done", "\n", "}", "\n", "}", "\n", "svc", ".", "restarts", "++", "\n", "svc", ".", "lastRestart", "=", "time", ".", "Now", "(", ")", "\n", "svc", ".", "runOnce", "(", ")", "\n", "select", "{", "case", "<-", "time", ".", "After", "(", "restartDelay", ")", ":", "case", "<-", "svc", ".", "shutdown", ":", "goto", "done", "\n", "}", "\n", "}", "\n", "done", ":", "svc", ".", "done", "<-", "true", "\n", "}" ]
// 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 } logLink := path.Join(logDir, name+".log") os.Remove(logLink) os.Symlink(logName, logLink) fmt.Fprintf(f, "Log file for %s (stdout/stderr)\n", name) fmt.Fprintf(f, "Created at: %s\n", t.Format("2006/01/02 15:04:05")) return f, nil }
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 } logLink := path.Join(logDir, name+".log") os.Remove(logLink) os.Symlink(logName, logLink) fmt.Fprintf(f, "Log file for %s (stdout/stderr)\n", name) fmt.Fprintf(f, "Created at: %s\n", t.Format("2006/01/02 15:04:05")) return f, nil }
[ "func", "(", "svc", "*", "Service", ")", "logFile", "(", ")", "(", "*", "os", ".", "File", ",", "error", ")", "{", "name", ":=", "\"seesaw_\"", "+", "svc", ".", "name", "\n", "t", ":=", "time", ".", "Now", "(", ")", "\n", "logName", ":=", "fmt", ".", "Sprintf", "(", "\"%s.log.%04d%02d%02d-%02d%02d%02d\"", ",", "name", ",", "t", ".", "Year", "(", ")", ",", "t", ".", "Month", "(", ")", ",", "t", ".", "Day", "(", ")", ",", "t", ".", "Hour", "(", ")", ",", "t", ".", "Minute", "(", ")", ",", "t", ".", "Second", "(", ")", ")", "\n", "f", ",", "err", ":=", "os", ".", "Create", "(", "path", ".", "Join", "(", "logDir", ",", "logName", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "logLink", ":=", "path", ".", "Join", "(", "logDir", ",", "name", "+", "\".log\"", ")", "\n", "os", ".", "Remove", "(", "logLink", ")", "\n", "os", ".", "Symlink", "(", "logName", ",", "logLink", ")", "\n", "fmt", ".", "Fprintf", "(", "f", ",", "\"Log file for %s (stdout/stderr)\\n\"", ",", "\\n", ")", "\n", "name", "\n", "fmt", ".", "Fprintf", "(", "f", ",", "\"Created at: %s\\n\"", ",", "\\n", ")", "\n", "}" ]
// 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", ".", "Warningf", "(", "\"Service %s - log sink failed: %v\"", ",", "svc", ".", "name", ",", "err", ")", "\n", "}", "\n", "f", ".", "Close", "(", ")", "\n", "r", ".", "Close", "(", ")", "\n", "}" ]
// 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", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "return", "svc", ".", "process", ".", "Signal", "(", "sig", ")", "\n", "}" ]
// 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 <- stopped } svc.shutdown <- true svc.signal(syscall.SIGTERM) select { case <-svc.done: case <-time.After(svc.termTimeout): svc.signal(syscall.SIGKILL) <-svc.done } log.Infof("Service %s stopped", svc.name) svc.stopped <- true }
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 <- stopped } svc.shutdown <- true svc.signal(syscall.SIGTERM) select { case <-svc.done: case <-time.After(svc.termTimeout): svc.signal(syscall.SIGKILL) <-svc.done } log.Infof("Service %s stopped", svc.name) svc.stopped <- true }
[ "func", "(", "svc", "*", "Service", ")", "stop", "(", ")", "{", "log", ".", "Infof", "(", "\"Stopping service %s...\"", ",", "svc", ".", "name", ")", "\n", "for", "_", ",", "dep", ":=", "range", "svc", ".", "dependents", "{", "log", ".", "Infof", "(", "\"Service %s waiting for %s to stop\"", ",", "svc", ".", "name", ",", "dep", ".", "name", ")", "\n", "stopped", ":=", "<-", "dep", ".", "stopped", "\n", "dep", ".", "stopped", "<-", "stopped", "\n", "}", "\n", "svc", ".", "shutdown", "<-", "true", "\n", "svc", ".", "signal", "(", "syscall", ".", "SIGTERM", ")", "\n", "select", "{", "case", "<-", "svc", ".", "done", ":", "case", "<-", "time", ".", "After", "(", "svc", ".", "termTimeout", ")", ":", "svc", ".", "signal", "(", "syscall", ".", "SIGKILL", ")", "\n", "<-", "svc", ".", "done", "\n", "}", "\n", "log", ".", "Infof", "(", "\"Service %s stopped\"", ",", "svc", ".", "name", ")", "\n", "svc", ".", "stopped", "<-", "true", "\n", "}" ]
// 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.Write(m.targetProtocolAddress) return buf.Bytes(), nil }
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.Write(m.targetProtocolAddress) return buf.Bytes(), nil }
[ "func", "(", "m", "*", "arpMessage", ")", "bytes", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "buf", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "if", "err", ":=", "binary", ".", "Write", "(", "buf", ",", "binary", ".", "BigEndian", ",", "m", ".", "arpHeader", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"binary write failed: %v\"", ",", "err", ")", "\n", "}", "\n", "buf", ".", "Write", "(", "m", ".", "senderHardwareAddress", ")", "\n", "buf", ".", "Write", "(", "m", ".", "senderProtocolAddress", ")", "\n", "buf", ".", "Write", "(", "m", ".", "targetHardwareAddress", ")", "\n", "buf", ".", "Write", "(", "m", ".", "targetProtocolAddress", ")", "\n", "return", "buf", ".", "Bytes", "(", ")", ",", "nil", "\n", "}" ]
// 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 0x0800, // IPv4 hwLen, // 48-bit MAC Address net.IPv4len, // 32-bit IPv4 Address opARPReply, // ARP Reply }, mac, ip.To4(), ethernetBroadcast, net.IPv4bcast, } return m, nil }
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 0x0800, // IPv4 hwLen, // 48-bit MAC Address net.IPv4len, // 32-bit IPv4 Address opARPReply, // ARP Reply }, mac, ip.To4(), ethernetBroadcast, net.IPv4bcast, } return m, nil }
[ "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", ")", "\n", "}", "\n", "if", "len", "(", "mac", ")", "!=", "hwLen", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"%q is not an Ethernet MAC address\"", ",", "mac", ")", "\n", "}", "\n", "m", ":=", "&", "arpMessage", "{", "arpHeader", "{", "1", ",", "0x0800", ",", "hwLen", ",", "net", ".", "IPv4len", ",", "opARPReply", ",", "}", ",", "mac", ",", "ip", ".", "To4", "(", ")", ",", "ethernetBroadcast", ",", "net", ".", "IPv4bcast", ",", "}", "\n", "return", "m", ",", "nil", "\n", "}" ]
// 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 { return fmt.Errorf("failed to bind to device: %v", err) } ll := syscall.SockaddrLinklayer{ Protocol: htons(syscall.ETH_P_ARP), Ifindex: iface.Index, Pkttype: 0, // syscall.PACKET_HOST Hatype: m.hardwareType, Halen: m.hardwareAddressLength, } target := ethernetBroadcast if m.opcode == opARPReply { target = m.targetHardwareAddress } for i := 0; i < len(target); i++ { ll.Addr[i] = target[i] } b, err := m.bytes() if err != nil { return fmt.Errorf("failed to convert ARP message: %v", err) } if err := syscall.Bind(fd, &ll); err != nil { return fmt.Errorf("failed to bind: %v", err) } if err := syscall.Sendto(fd, b, 0, &ll); err != nil { return fmt.Errorf("failed to send: %v", err) } return 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 { return fmt.Errorf("failed to bind to device: %v", err) } ll := syscall.SockaddrLinklayer{ Protocol: htons(syscall.ETH_P_ARP), Ifindex: iface.Index, Pkttype: 0, // syscall.PACKET_HOST Hatype: m.hardwareType, Halen: m.hardwareAddressLength, } target := ethernetBroadcast if m.opcode == opARPReply { target = m.targetHardwareAddress } for i := 0; i < len(target); i++ { ll.Addr[i] = target[i] } b, err := m.bytes() if err != nil { return fmt.Errorf("failed to convert ARP message: %v", err) } if err := syscall.Bind(fd, &ll); err != nil { return fmt.Errorf("failed to bind: %v", err) } if err := syscall.Sendto(fd, b, 0, &ll); err != nil { return fmt.Errorf("failed to send: %v", err) } return nil }
[ "func", "sendARP", "(", "iface", "*", "net", ".", "Interface", ",", "m", "*", "arpMessage", ")", "error", "{", "fd", ",", "err", ":=", "syscall", ".", "Socket", "(", "syscall", ".", "AF_PACKET", ",", "syscall", ".", "SOCK_DGRAM", ",", "int", "(", "htons", "(", "syscall", ".", "ETH_P_ARP", ")", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"failed to get raw socket: %v\"", ",", "err", ")", "\n", "}", "\n", "defer", "syscall", ".", "Close", "(", "fd", ")", "\n", "if", "err", ":=", "syscall", ".", "BindToDevice", "(", "fd", ",", "iface", ".", "Name", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"failed to bind to device: %v\"", ",", "err", ")", "\n", "}", "\n", "ll", ":=", "syscall", ".", "SockaddrLinklayer", "{", "Protocol", ":", "htons", "(", "syscall", ".", "ETH_P_ARP", ")", ",", "Ifindex", ":", "iface", ".", "Index", ",", "Pkttype", ":", "0", ",", "Hatype", ":", "m", ".", "hardwareType", ",", "Halen", ":", "m", ".", "hardwareAddressLength", ",", "}", "\n", "target", ":=", "ethernetBroadcast", "\n", "if", "m", ".", "opcode", "==", "opARPReply", "{", "target", "=", "m", ".", "targetHardwareAddress", "\n", "}", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "target", ")", ";", "i", "++", "{", "ll", ".", "Addr", "[", "i", "]", "=", "target", "[", "i", "]", "\n", "}", "\n", "b", ",", "err", ":=", "m", ".", "bytes", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"failed to convert ARP message: %v\"", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "syscall", ".", "Bind", "(", "fd", ",", "&", "ll", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"failed to bind: %v\"", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "syscall", ".", "Sendto", "(", "fd", ",", "b", ",", "0", ",", "&", "ll", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"failed to send: %v\"", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// 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, iface.Name) m, err := gratuitousARPReply(arp.IP, iface.HardwareAddr) if err != nil { return err } return sendARP(iface, m) }
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, iface.Name) m, err := gratuitousARPReply(arp.IP, iface.HardwareAddr) if err != nil { return err } return sendARP(iface, m) }
[ "func", "(", "ncc", "*", "SeesawNCC", ")", "ARPSendGratuitous", "(", "arp", "*", "ncctypes", ".", "ARPGratuitous", ",", "out", "*", "int", ")", "error", "{", "iface", ",", "err", ":=", "net", ".", "InterfaceByName", "(", "arp", ".", "IfaceName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"failed to get interface %q: %v\"", ",", "arp", ".", "IfaceName", ",", "err", ")", "\n", "}", "\n", "log", ".", "V", "(", "2", ")", ".", "Infof", "(", "\"Sending gratuitous ARP for %s (%s) via %s\"", ",", "arp", ".", "IP", ",", "iface", ".", "HardwareAddr", ",", "iface", ".", "Name", ")", "\n", "m", ",", "err", ":=", "gratuitousARPReply", "(", "arp", ".", "IP", ",", "iface", ".", "HardwareAddr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "sendARP", "(", "iface", ",", "m", ")", "\n", "}" ]
// 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", "(", "\"(unknown %d)\"", ",", "rc", ")", "\n", "}" ]
// 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", "(", "\"(unknown %d)\"", ",", "rat", ")", "\n", "}" ]
// 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.Write([]byte(secret)) if i >= blockSize { hash.Write(blocks[i-blockSize : i]) } else { hash.Write(authenticator[:]) } h := hash.Sum(nil) for j := 0; j < blockSize; j++ { blocks[i+j] ^= h[j] } } return blocks }
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.Write([]byte(secret)) if i >= blockSize { hash.Write(blocks[i-blockSize : i]) } else { hash.Write(authenticator[:]) } h := hash.Sum(nil) for j := 0; j < blockSize; j++ { blocks[i+j] ^= h[j] } } return blocks }
[ "func", "radiusPassword", "(", "passwd", ",", "secret", "string", ",", "authenticator", "*", "radiusAuthenticator", ")", "[", "]", "byte", "{", "const", "blockSize", "=", "16", "\n", "length", ":=", "(", "len", "(", "passwd", ")", "+", "0xf", ")", "&^", "0xf", "\n", "if", "length", ">", "128", "{", "length", "=", "128", "\n", "}", "\n", "blocks", ":=", "make", "(", "[", "]", "byte", ",", "length", ")", "\n", "copy", "(", "blocks", ",", "[", "]", "byte", "(", "passwd", ")", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "length", ";", "i", "+=", "blockSize", "{", "hash", ":=", "md5", ".", "New", "(", ")", "\n", "hash", ".", "Write", "(", "[", "]", "byte", "(", "secret", ")", ")", "\n", "if", "i", ">=", "blockSize", "{", "hash", ".", "Write", "(", "blocks", "[", "i", "-", "blockSize", ":", "i", "]", ")", "\n", "}", "else", "{", "hash", ".", "Write", "(", "authenticator", "[", ":", "]", ")", "\n", "}", "\n", "h", ":=", "hash", ".", "Sum", "(", "nil", ")", "\n", "for", "j", ":=", "0", ";", "j", "<", "blockSize", ";", "j", "++", "{", "blocks", "[", "i", "+", "j", "]", "^=", "h", "[", "j", "]", "\n", "}", "\n", "}", "\n", "return", "blocks", "\n", "}" ]
// 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(requestAuthenticator[:]) for _, ra := range rp.attributes { hash.Write(ra.encode()) } hash.Write([]byte(secret)) h := hash.Sum(nil) var authenticator radiusAuthenticator copy(authenticator[:], h[:]) return &authenticator, nil }
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(requestAuthenticator[:]) for _, ra := range rp.attributes { hash.Write(ra.encode()) } hash.Write([]byte(secret)) h := hash.Sum(nil) var authenticator radiusAuthenticator copy(authenticator[:], h[:]) return &authenticator, nil }
[ "func", "responseAuthenticator", "(", "rp", "*", "radiusPacket", ",", "requestAuthenticator", "*", "radiusAuthenticator", ",", "secret", "string", ")", "(", "*", "radiusAuthenticator", ",", "error", ")", "{", "hash", ":=", "md5", ".", "New", "(", ")", "\n", "hash", ".", "Write", "(", "[", "]", "byte", "{", "byte", "(", "rp", ".", "Code", ")", ",", "byte", "(", "rp", ".", "Identifier", ")", "}", ")", "\n", "if", "err", ":=", "binary", ".", "Write", "(", "hash", ",", "binary", ".", "BigEndian", ",", "rp", ".", "Length", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "hash", ".", "Write", "(", "requestAuthenticator", "[", ":", "]", ")", "\n", "for", "_", ",", "ra", ":=", "range", "rp", ".", "attributes", "{", "hash", ".", "Write", "(", "ra", ".", "encode", "(", ")", ")", "\n", "}", "\n", "hash", ".", "Write", "(", "[", "]", "byte", "(", "secret", ")", ")", "\n", "h", ":=", "hash", ".", "Sum", "(", "nil", ")", "\n", "var", "authenticator", "radiusAuthenticator", "\n", "copy", "(", "authenticator", "[", ":", "]", ",", "h", "[", ":", "]", ")", "\n", "return", "&", "authenticator", ",", "nil", "\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", ".", "IPProtoUDP", ",", "}", ",", "Response", ":", "\"accept\"", ",", "}", "\n", "}" ]
// 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.ConfigStatus{ Warnings: make([]string, 0), Attributes: make([]seesaw.ConfigMetadata, 0), }, } }
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.ConfigStatus{ Warnings: make([]string, 0), Attributes: make([]seesaw.ConfigMetadata, 0), }, } }
[ "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", ".", "ConfigStatus", "{", "Warnings", ":", "make", "(", "[", "]", "string", ",", "0", ")", ",", "Attributes", ":", "make", "(", "[", "]", "seesaw", ".", "ConfigMetadata", ",", "0", ")", ",", "}", ",", "}", "\n", "}" ]
// 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", "{", "return", "fmt", ".", "Errorf", "(", "\"Cluster %q already contains peer %q\"", ",", "c", ".", "Site", ",", "key", ")", "\n", "}", "\n", "c", ".", "BGPPeers", "[", "key", "]", "=", "peer", "\n", "return", "nil", "\n", "}" ]
// 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", "{", "return", "fmt", ".", "Errorf", "(", "\"Cluster %q already contains Node %q\"", ",", "c", ".", "Site", ",", "key", ")", "\n", "}", "\n", "c", ".", "Nodes", "[", "key", "]", "=", "node", "\n", "return", "nil", "\n", "}" ]
// 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", "]", ";", "ok", "{", "return", "fmt", ".", "Errorf", "(", "\"Cluster %q already contains VIP Subnet %q\"", ",", "c", ".", "Site", ",", "key", ")", "\n", "}", "\n", "c", ".", "VIPSubnets", "[", "key", "]", "=", "subnet", "\n", "return", "nil", "\n", "}" ]
// 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", "{", "return", "fmt", ".", "Errorf", "(", "\"Cluster %q already contains Vserver %q\"", ",", "c", ".", "Site", ",", "key", ")", "\n", "}", "\n", "c", ".", "Vservers", "[", "key", "]", "=", "vserver", "\n", "return", "nil", "\n", "}" ]
// 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", "{", "return", "fmt", ".", "Errorf", "(", "\"Cluster %q already contains VLAN %q\"", ",", "c", ".", "Site", ",", "key", ")", "\n", "}", "\n", "c", ".", "VLANs", "[", "key", "]", "=", "vlan", "\n", "return", "nil", "\n", "}" ]
// 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), Warnings: make([]string, 0), } }
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), Warnings: make([]string, 0), } }
[ "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", ")", ",", "Warnings", ":", "make", "(", "[", "]", "string", ",", "0", ")", ",", "}", "\n", "}" ]
// 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", "fmt", ".", "Errorf", "(", "\"Vserver %q already contains VserverEntry %q\"", ",", "v", ".", "Name", ",", "key", ")", "\n", "}", "\n", "v", ".", "Entries", "[", "key", "]", "=", "e", "\n", "return", "nil", "\n", "}" ]
// 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", "]", ";", "ok", "{", "return", "fmt", ".", "Errorf", "(", "\"Vserver %q already contains Backend %q\"", ",", "v", ".", "Name", ",", "key", ")", "\n", "}", "\n", "v", ".", "Backends", "[", "key", "]", "=", "backend", "\n", "return", "nil", "\n", "}" ]
// 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", "{", "return", "fmt", ".", "Errorf", "(", "\"Vserver %q already contains Healthcheck %q\"", ",", "v", ".", "Name", ",", "key", ")", "\n", "}", "\n", "v", ".", "Healthchecks", "[", "key", "]", "=", "h", "\n", "return", "nil", "\n", "}" ]
// 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", "{", "return", "fmt", ".", "Errorf", "(", "\"Vserver %q already contains VIP %q\"", ",", "v", ".", "Name", ",", "key", ")", "\n", "}", "\n", "v", ".", "VIPs", "[", "key", "]", "=", "vip", "\n", "return", "nil", "\n", "}" ]
// 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", "[", "string", "]", "*", "Healthcheck", ")", ",", "}", "\n", "}" ]
// 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", "(", "\"%d/%s\"", ",", "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, LThreshold: v.LThreshold, UThreshold: v.UThreshold, } }
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, LThreshold: v.LThreshold, UThreshold: v.UThreshold, } }
[ "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", ",", "LThreshold", ":", "v", ".", "LThreshold", ",", "UThreshold", ":", "v", ".", "UThreshold", ",", "}", "\n", "}" ]
// 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", ":", "port", ",", "}", "\n", "}" ]
// 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", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "err", ":=", "bgp", ".", "Enable", "(", ")", ";", "err", "!=", "nil", "{", "bgp", ".", "Close", "(", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n", "return", "bgp", ",", "nil", "\n", "}" ]
// 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", "err", "\n", "}", "\n", "defer", "bgp", ".", "Close", "(", ")", "\n", "bgpCfg", ",", "err", ":=", "bgp", ".", "Configuration", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "cfg", "!=", "nil", "{", "cfg", ".", "Config", "=", "bgpCfg", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// 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", "{", "return", "err", "\n", "}", "\n", "defer", "bgp", ".", "Close", "(", ")", "\n", "bgpNeighbors", ",", "err", ":=", "bgp", ".", "Neighbors", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "neighbors", "!=", "nil", "{", "neighbors", ".", "Neighbors", "=", "bgpNeighbors", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// 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", "=", "net", ".", "IPv6len", "*", "8", "\n", "}", "\n", "return", "net", ".", "CIDRMask", "(", "hl", ",", "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 bgp %d", seesawASN) found := false for _, line := range bgpCfg { if line == bgpStr { found = true continue } if !found || line == "!" { continue } if !strings.HasPrefix(line, " ") { break } if strings.HasPrefix(line, " network ") { n := strings.Replace(line, " network ", "", 1) vip, ipNet, err := net.ParseCIDR(n) if err != nil { return err } err = bgp.Withdraw(&net.IPNet{IP: vip, Mask: ipNet.Mask}) if err != nil { return err } } } return nil }
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 bgp %d", seesawASN) found := false for _, line := range bgpCfg { if line == bgpStr { found = true continue } if !found || line == "!" { continue } if !strings.HasPrefix(line, " ") { break } if strings.HasPrefix(line, " network ") { n := strings.Replace(line, " network ", "", 1) vip, ipNet, err := net.ParseCIDR(n) if err != nil { return err } err = bgp.Withdraw(&net.IPNet{IP: vip, Mask: ipNet.Mask}) if err != nil { return err } } } return nil }
[ "func", "(", "ncc", "*", "SeesawNCC", ")", "BGPWithdrawAll", "(", "unused", "int", ",", "reply", "*", "int", ")", "error", "{", "bgp", ",", "err", ":=", "quaggaBGP", "(", "seesawASN", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "bgp", ".", "Close", "(", ")", "\n", "bgpCfg", ",", "err", ":=", "bgp", ".", "Configuration", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "bgpStr", ":=", "fmt", ".", "Sprintf", "(", "\"router bgp %d\"", ",", "seesawASN", ")", "\n", "found", ":=", "false", "\n", "for", "_", ",", "line", ":=", "range", "bgpCfg", "{", "if", "line", "==", "bgpStr", "{", "found", "=", "true", "\n", "continue", "\n", "}", "\n", "if", "!", "found", "||", "line", "==", "\"!\"", "{", "continue", "\n", "}", "\n", "if", "!", "strings", ".", "HasPrefix", "(", "line", ",", "\" \"", ")", "{", "break", "\n", "}", "\n", "if", "strings", ".", "HasPrefix", "(", "line", ",", "\" network \"", ")", "{", "n", ":=", "strings", ".", "Replace", "(", "line", ",", "\" network \"", ",", "\"\"", ",", "1", ")", "\n", "vip", ",", "ipNet", ",", "err", ":=", "net", ".", "ParseCIDR", "(", "n", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "err", "=", "bgp", ".", "Withdraw", "(", "&", "net", ".", "IPNet", "{", "IP", ":", "vip", ",", "Mask", ":", "ipNet", ".", "Mask", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "nil", "\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", "err", "\n", "}", "\n", "defer", "bgp", ".", "Close", "(", ")", "\n", "return", "bgp", ".", "Advertise", "(", "&", "net", ".", "IPNet", "{", "IP", ":", "vip", ",", "Mask", ":", "hostMask", "(", "vip", ")", "}", ")", "\n", "}" ]
// 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(chan seesaw.HAStatus, 1), } }
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(chan seesaw.HAStatus, 1), } }
[ "func", "newHAManager", "(", "engine", "*", "Engine", ",", "timeout", "time", ".", "Duration", ")", "*", "haManager", "{", "now", ":=", "time", ".", "Now", "(", ")", "\n", "return", "&", "haManager", "{", "engine", ":", "engine", ",", "status", ":", "seesaw", ".", "HAStatus", "{", "LastUpdate", ":", "now", ",", "Since", ":", "now", ",", "State", ":", "seesaw", ".", "HAUnknown", ",", "}", ",", "timeout", ":", "timeout", ",", "stateChan", ":", "make", "(", "chan", "seesaw", ".", "HAState", ",", "1", ")", ",", "statusChan", ":", "make", "(", "chan", "seesaw", ".", "HAStatus", ",", "1", ")", ",", "}", "\n", "}" ]
// 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", "\n", "}" ]
// 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", ".", "failoverLock", ".", "Unlock", "(", ")", "\n", "return", "pending", "\n", "}" ]
// 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.Errorf("Node is not master (current state is %v)", state) } if err := h.engine.syncClient.failover(); err != nil { return err } return nil }
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.Errorf("Node is not master (current state is %v)", state) } if err := h.engine.syncClient.failover(); err != nil { return err } return nil }
[ "func", "(", "h", "*", "haManager", ")", "requestFailover", "(", "peer", "bool", ")", "error", "{", "state", ":=", "h", ".", "state", "(", ")", "\n", "if", "state", "==", "seesaw", ".", "HAMaster", "{", "h", ".", "failoverLock", ".", "Lock", "(", ")", "\n", "defer", "h", ".", "failoverLock", ".", "Unlock", "(", ")", "\n", "if", "h", ".", "failoverPending", "{", "return", "fmt", ".", "Errorf", "(", "\"Failover request already pending\"", ")", "\n", "}", "\n", "h", ".", "failoverPending", "=", "true", "\n", "return", "nil", "\n", "}", "\n", "if", "peer", "{", "return", "fmt", ".", "Errorf", "(", "\"Node is not master (current state is %v)\"", ",", "state", ")", "\n", "}", "\n", "if", "err", ":=", "h", ".", "engine", ".", "syncClient", ".", "failover", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// 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.engine.becomeMaster() } else if state == seesaw.HAMaster || s == seesaw.HABackup { h.engine.becomeBackup() } log.Infof("HA state transition %v -> %v complete", state, s) } now := time.Now() h.statusLock.Lock() h.status.State = s h.status.Since = now h.status.LastUpdate = now h.statusLock.Unlock() }
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.engine.becomeMaster() } else if state == seesaw.HAMaster || s == seesaw.HABackup { h.engine.becomeBackup() } log.Infof("HA state transition %v -> %v complete", state, s) } now := time.Now() h.statusLock.Lock() h.status.State = s h.status.Since = now h.status.LastUpdate = now h.statusLock.Unlock() }
[ "func", "(", "h", "*", "haManager", ")", "setState", "(", "s", "seesaw", ".", "HAState", ")", "{", "state", ":=", "h", ".", "state", "(", ")", "\n", "if", "state", "==", "seesaw", ".", "HADisabled", "&&", "s", "!=", "seesaw", ".", "HAUnknown", "{", "log", ".", "Warningf", "(", "\"Invalid HA state transition %v -> %v\"", ",", "state", ",", "s", ")", "\n", "return", "\n", "}", "\n", "if", "state", "!=", "s", "{", "log", ".", "Infof", "(", "\"HA state transition %v -> %v starting\"", ",", "state", ",", "s", ")", "\n", "if", "s", "==", "seesaw", ".", "HAMaster", "{", "h", ".", "engine", ".", "becomeMaster", "(", ")", "\n", "}", "else", "if", "state", "==", "seesaw", ".", "HAMaster", "||", "s", "==", "seesaw", ".", "HABackup", "{", "h", ".", "engine", ".", "becomeBackup", "(", ")", "\n", "}", "\n", "log", ".", "Infof", "(", "\"HA state transition %v -> %v complete\"", ",", "state", ",", "s", ")", "\n", "}", "\n", "now", ":=", "time", ".", "Now", "(", ")", "\n", "h", ".", "statusLock", ".", "Lock", "(", ")", "\n", "h", ".", "status", ".", "State", "=", "s", "\n", "h", ".", "status", ".", "Since", "=", "now", "\n", "h", ".", "status", ".", "LastUpdate", "=", "now", "\n", "h", ".", "statusLock", ".", "Unlock", "(", ")", "\n", "}" ]
// 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", "h", ".", "statusLock", ".", "Lock", "(", ")", "\n", "h", ".", "status", ".", "Since", "=", "s", ".", "Since", "\n", "h", ".", "status", ".", "Sent", "=", "s", ".", "Sent", "\n", "h", ".", "status", ".", "Received", "=", "s", ".", "Received", "\n", "h", ".", "status", ".", "Transitions", "=", "s", ".", "Transitions", "\n", "h", ".", "statusLock", ".", "Unlock", "(", ")", "\n", "}" ]
// 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(time.Now())) }
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(time.Now())) }
[ "func", "(", "h", "*", "haManager", ")", "timer", "(", ")", "<-", "chan", "time", ".", "Time", "{", "if", "s", ":=", "h", ".", "state", "(", ")", ";", "s", "==", "seesaw", ".", "HADisabled", "||", "s", "==", "seesaw", ".", "HAUnknown", "{", "return", "make", "(", "chan", "time", ".", "Time", ")", "\n", "}", "\n", "h", ".", "statusLock", ".", "RLock", "(", ")", "\n", "deadline", ":=", "h", ".", "status", ".", "LastUpdate", ".", "Add", "(", "h", ".", "timeout", ")", "\n", "h", ".", "statusLock", ".", "RUnlock", "(", ")", "\n", "return", "time", ".", "After", "(", "deadline", ".", "Sub", "(", "time", ".", "Now", "(", ")", ")", ")", "\n", "}" ]
// 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", ".", "function", "(", "cli", ",", "args", ")", "\n", "}", "\n", "if", "subcmds", "!=", "nil", "{", "return", "errors", ".", "New", "(", "\"Incomplete command.\"", ")", "\n", "}", "\n", "return", "errors", ".", "New", "(", "\"Unknown command.\"", ")", "\n", "}" ]
// 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 { matches = make([]Command, 0) next = nil for i := range *cmds { cmd := (*cmds)[i] if strings.HasPrefix(cmd.Command, subcmd) { matches = append(matches, cmd) next = &cmd } } if len(matches) == 0 { // Sub command not found. return nil, nil, chain, cmdstr[idx:] } else if len(matches) > 1 { // Ambiguious command. return nil, &matches, chain, cmdstr[idx:] } chain = append(chain, next) if next.function != nil { // We've reached a function. return next, nil, chain, cmdstr[idx+1:] } else { cmds = next.Subcommands } } if next != nil { return nil, next.Subcommands, chain, nil } return nil, nil, chain, nil }
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 { matches = make([]Command, 0) next = nil for i := range *cmds { cmd := (*cmds)[i] if strings.HasPrefix(cmd.Command, subcmd) { matches = append(matches, cmd) next = &cmd } } if len(matches) == 0 { // Sub command not found. return nil, nil, chain, cmdstr[idx:] } else if len(matches) > 1 { // Ambiguious command. return nil, &matches, chain, cmdstr[idx:] } chain = append(chain, next) if next.function != nil { // We've reached a function. return next, nil, chain, cmdstr[idx+1:] } else { cmds = next.Subcommands } } if next != nil { return nil, next.Subcommands, chain, nil } return nil, nil, chain, nil }
[ "func", "FindCommand", "(", "cmdline", "string", ")", "(", "*", "Command", ",", "*", "[", "]", "Command", ",", "[", "]", "*", "Command", ",", "[", "]", "string", ")", "{", "var", "chain", "[", "]", "*", "Command", "\n", "var", "matches", "[", "]", "Command", "\n", "var", "next", "*", "Command", "\n", "cmds", ":=", "&", "commands", "\n", "cmdstr", ":=", "strings", ".", "Fields", "(", "cmdline", ")", "\n", "if", "len", "(", "cmdstr", ")", "==", "0", "{", "return", "nil", ",", "cmds", ",", "chain", ",", "nil", "\n", "}", "\n", "for", "idx", ",", "subcmd", ":=", "range", "cmdstr", "{", "matches", "=", "make", "(", "[", "]", "Command", ",", "0", ")", "\n", "next", "=", "nil", "\n", "for", "i", ":=", "range", "*", "cmds", "{", "cmd", ":=", "(", "*", "cmds", ")", "[", "i", "]", "\n", "if", "strings", ".", "HasPrefix", "(", "cmd", ".", "Command", ",", "subcmd", ")", "{", "matches", "=", "append", "(", "matches", ",", "cmd", ")", "\n", "next", "=", "&", "cmd", "\n", "}", "\n", "}", "\n", "if", "len", "(", "matches", ")", "==", "0", "{", "return", "nil", ",", "nil", ",", "chain", ",", "cmdstr", "[", "idx", ":", "]", "\n", "}", "else", "if", "len", "(", "matches", ")", ">", "1", "{", "return", "nil", ",", "&", "matches", ",", "chain", ",", "cmdstr", "[", "idx", ":", "]", "\n", "}", "\n", "chain", "=", "append", "(", "chain", ",", "next", ")", "\n", "if", "next", ".", "function", "!=", "nil", "{", "return", "next", ",", "nil", ",", "chain", ",", "cmdstr", "[", "idx", "+", "1", ":", "]", "\n", "}", "else", "{", "cmds", "=", "next", ".", "Subcommands", "\n", "}", "\n", "}", "\n", "if", "next", "!=", "nil", "{", "return", "nil", ",", "next", ".", "Subcommands", ",", "chain", ",", "nil", "\n", "}", "\n", "return", "nil", ",", "nil", ",", "chain", ",", "nil", "\n", "}" ]
// 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 with the slice of remaining arguments.
[ "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", "with", "the", "slice", "of", "remaining", "arguments", "." ]
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", "\"Unknown\"", "\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", "]", ")", "==", "name", "{", "return", "s", "\n", "}", "\n", "}", "\n", "return", "BGPStateUnknown", "\n", "}" ]
// 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", ")", ",", "asn", ":", "asn", ",", "}", "\n", "}" ]
// 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", "(", "\"enable\"", ")", "\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", "(", "\"write terminal\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "strings", ".", "Split", "(", "cfg", ",", "\"\\n\"", ")", ",", "nil", "\n", "}" ]
// 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", "(", "\"show ip bgp neighbors\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "parseNeighbors", "(", "ni", ")", ",", "nil", "\n", "}" ]
// 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("address-family %s", family), fmt.Sprintf("%snetwork %s/%d", prefix, n.IP, prefixLen), "end", } bgpConfigLock.Lock() defer bgpConfigLock.Unlock() return b.vty.Commands(cmds) }
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("address-family %s", family), fmt.Sprintf("%snetwork %s/%d", prefix, n.IP, prefixLen), "end", } bgpConfigLock.Lock() defer bgpConfigLock.Unlock() return b.vty.Commands(cmds) }
[ "func", "(", "b", "*", "BGP", ")", "network", "(", "n", "*", "net", ".", "IPNet", ",", "advertise", "bool", ")", "error", "{", "var", "prefix", "string", "\n", "if", "!", "advertise", "{", "prefix", "=", "\"no \"", "\n", "}", "\n", "family", ":=", "\"ipv4 unicast\"", "\n", "if", "n", ".", "IP", ".", "To4", "(", ")", "==", "nil", "{", "family", "=", "\"ipv6\"", "\n", "}", "\n", "prefixLen", ",", "_", ":=", "n", ".", "Mask", ".", "Size", "(", ")", "\n", "cmds", ":=", "[", "]", "string", "{", "\"configure terminal\"", ",", "fmt", ".", "Sprintf", "(", "\"router bgp %d\"", ",", "b", ".", "asn", ")", ",", "fmt", ".", "Sprintf", "(", "\"address-family %s\"", ",", "family", ")", ",", "fmt", ".", "Sprintf", "(", "\"%snetwork %s/%d\"", ",", "prefix", ",", "n", ".", "IP", ",", "prefixLen", ")", ",", "\"end\"", ",", "}", "\n", "bgpConfigLock", ".", "Lock", "(", ")", "\n", "defer", "bgpConfigLock", ".", "Unlock", "(", ")", "\n", "return", "b", ".", "vty", ".", "Commands", "(", "cmds", ")", "\n", "}" ]
// 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[1]), ASN: uint32(asn), } neighbors = append(neighbors, neighbor) } if neighbor == nil { continue } if msgStats { if nm := neighborStatsRE.FindStringSubmatch(s); nm != nil { var ms *MessageStat switch nm[1] { case "Opens": ms = &neighbor.Opens case "Notifications": ms = &neighbor.Notifications case "Updates": ms = &neighbor.Updates case "Keepalives": ms = &neighbor.Keepalives case "Route Refresh": ms = &neighbor.RouteRefresh case "Capability": ms = &neighbor.Capability case "Total": ms = &neighbor.Total msgStats = false } if ms != nil { sent, _ := strconv.ParseUint(nm[2], 10, 0) ms.Sent = sent rcvd, _ := strconv.ParseUint(nm[3], 10, 0) ms.Rcvd = rcvd } } } if nm := neighborDescRE.FindStringSubmatch(s); nm != nil { neighbor.Description = nm[1] } else if nm := neighborStateRE.FindStringSubmatch(s); nm != nil { neighbor.BGPState = BGPStateByName(nm[1]) neighbor.Uptime = ParseUptime(nm[3]) } else if nm := neighborVersionRE.FindStringSubmatch(s); nm != nil { neighbor.RouterID = net.ParseIP(nm[2]) } else if s == " Message statistics:" { msgStats = true } } return neighbors }
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[1]), ASN: uint32(asn), } neighbors = append(neighbors, neighbor) } if neighbor == nil { continue } if msgStats { if nm := neighborStatsRE.FindStringSubmatch(s); nm != nil { var ms *MessageStat switch nm[1] { case "Opens": ms = &neighbor.Opens case "Notifications": ms = &neighbor.Notifications case "Updates": ms = &neighbor.Updates case "Keepalives": ms = &neighbor.Keepalives case "Route Refresh": ms = &neighbor.RouteRefresh case "Capability": ms = &neighbor.Capability case "Total": ms = &neighbor.Total msgStats = false } if ms != nil { sent, _ := strconv.ParseUint(nm[2], 10, 0) ms.Sent = sent rcvd, _ := strconv.ParseUint(nm[3], 10, 0) ms.Rcvd = rcvd } } } if nm := neighborDescRE.FindStringSubmatch(s); nm != nil { neighbor.Description = nm[1] } else if nm := neighborStateRE.FindStringSubmatch(s); nm != nil { neighbor.BGPState = BGPStateByName(nm[1]) neighbor.Uptime = ParseUptime(nm[3]) } else if nm := neighborVersionRE.FindStringSubmatch(s); nm != nil { neighbor.RouterID = net.ParseIP(nm[2]) } else if s == " Message statistics:" { msgStats = true } } return neighbors }
[ "func", "parseNeighbors", "(", "sn", "string", ")", "[", "]", "*", "Neighbor", "{", "neighbors", ":=", "make", "(", "[", "]", "*", "Neighbor", ",", "0", ")", "\n", "var", "neighbor", "*", "Neighbor", "\n", "var", "msgStats", "bool", "\n", "for", "_", ",", "s", ":=", "range", "strings", ".", "Split", "(", "sn", ",", "\"\\n\"", ")", "\\n", "\n", "{", "if", "nm", ":=", "neighborRE", ".", "FindStringSubmatch", "(", "s", ")", ";", "nm", "!=", "nil", "{", "asn", ",", "_", ":=", "strconv", ".", "ParseUint", "(", "nm", "[", "2", "]", ",", "10", ",", "32", ")", "\n", "neighbor", "=", "&", "Neighbor", "{", "IP", ":", "net", ".", "ParseIP", "(", "nm", "[", "1", "]", ")", ",", "ASN", ":", "uint32", "(", "asn", ")", ",", "}", "\n", "neighbors", "=", "append", "(", "neighbors", ",", "neighbor", ")", "\n", "}", "\n", "if", "neighbor", "==", "nil", "{", "continue", "\n", "}", "\n", "if", "msgStats", "{", "if", "nm", ":=", "neighborStatsRE", ".", "FindStringSubmatch", "(", "s", ")", ";", "nm", "!=", "nil", "{", "var", "ms", "*", "MessageStat", "\n", "switch", "nm", "[", "1", "]", "{", "case", "\"Opens\"", ":", "ms", "=", "&", "neighbor", ".", "Opens", "\n", "case", "\"Notifications\"", ":", "ms", "=", "&", "neighbor", ".", "Notifications", "\n", "case", "\"Updates\"", ":", "ms", "=", "&", "neighbor", ".", "Updates", "\n", "case", "\"Keepalives\"", ":", "ms", "=", "&", "neighbor", ".", "Keepalives", "\n", "case", "\"Route Refresh\"", ":", "ms", "=", "&", "neighbor", ".", "RouteRefresh", "\n", "case", "\"Capability\"", ":", "ms", "=", "&", "neighbor", ".", "Capability", "\n", "case", "\"Total\"", ":", "ms", "=", "&", "neighbor", ".", "Total", "\n", "msgStats", "=", "false", "\n", "}", "\n", "if", "ms", "!=", "nil", "{", "sent", ",", "_", ":=", "strconv", ".", "ParseUint", "(", "nm", "[", "2", "]", ",", "10", ",", "0", ")", "\n", "ms", ".", "Sent", "=", "sent", "\n", "rcvd", ",", "_", ":=", "strconv", ".", "ParseUint", "(", "nm", "[", "3", "]", ",", "10", ",", "0", ")", "\n", "ms", ".", "Rcvd", "=", "rcvd", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "nm", ":=", "neighborDescRE", ".", "FindStringSubmatch", "(", "s", ")", ";", "nm", "!=", "nil", "{", "neighbor", ".", "Description", "=", "nm", "[", "1", "]", "\n", "}", "else", "if", "nm", ":=", "neighborStateRE", ".", "FindStringSubmatch", "(", "s", ")", ";", "nm", "!=", "nil", "{", "neighbor", ".", "BGPState", "=", "BGPStateByName", "(", "nm", "[", "1", "]", ")", "\n", "neighbor", ".", "Uptime", "=", "ParseUptime", "(", "nm", "[", "3", "]", ")", "\n", "}", "else", "if", "nm", ":=", "neighborVersionRE", ".", "FindStringSubmatch", "(", "s", ")", ";", "nm", "!=", "nil", "{", "neighbor", ".", "RouterID", "=", "net", ".", "ParseIP", "(", "nm", "[", "2", "]", ")", "\n", "}", "else", "if", "s", "==", "\" Message statistics:\"", "{", "msgStats", "=", "true", "\n", "}", "\n", "}", "\n", "}" ]
// 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", ".", "IPProtoUDP", ",", "}", ",", "}", "\n", "}" ]
// 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 = fmt.Sprintf("%s; failed to create socket", msg) return complete(start, msg, false, err) } defer conn.Close() err = conn.SetDeadline(deadline) if err != nil { msg = fmt.Sprintf("%s; failed to set deadline", msg) return complete(start, msg, false, err) } if _, err = conn.Write([]byte(hc.Send)); err != nil { msg = fmt.Sprintf("%s; failed to send request", msg) return complete(start, msg, false, err) } buf := make([]byte, len(hc.Receive)) n, _, err := conn.ReadFrom(buf) if err != nil { msg = fmt.Sprintf("%s; failed to read response", msg) return complete(start, msg, false, err) } got := string(buf[0:n]) if got != hc.Receive { msg = fmt.Sprintf("%s; unexpected response - %q", msg, got) return complete(start, msg, false, err) } return complete(start, msg, true, err) }
go
func (hc *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 = fmt.Sprintf("%s; failed to create socket", msg) return complete(start, msg, false, err) } defer conn.Close() err = conn.SetDeadline(deadline) if err != nil { msg = fmt.Sprintf("%s; failed to set deadline", msg) return complete(start, msg, false, err) } if _, err = conn.Write([]byte(hc.Send)); err != nil { msg = fmt.Sprintf("%s; failed to send request", msg) return complete(start, msg, false, err) } buf := make([]byte, len(hc.Receive)) n, _, err := conn.ReadFrom(buf) if err != nil { msg = fmt.Sprintf("%s; failed to read response", msg) return complete(start, msg, false, err) } got := string(buf[0:n]) if got != hc.Receive { msg = fmt.Sprintf("%s; unexpected response - %q", msg, got) return complete(start, msg, false, err) } return complete(start, msg, true, err) }
[ "func", "(", "hc", "*", "UDPChecker", ")", "Check", "(", "timeout", "time", ".", "Duration", ")", "*", "Result", "{", "msg", ":=", "fmt", ".", "Sprintf", "(", "\"UDP check to %s\"", ",", "hc", ".", "addr", "(", ")", ")", "\n", "start", ":=", "time", ".", "Now", "(", ")", "\n", "if", "timeout", "==", "time", ".", "Duration", "(", "0", ")", "{", "timeout", "=", "defaultUDPTimeout", "\n", "}", "\n", "deadline", ":=", "start", ".", "Add", "(", "timeout", ")", "\n", "conn", ",", "err", ":=", "dialUDP", "(", "hc", ".", "network", "(", ")", ",", "hc", ".", "addr", "(", ")", ",", "timeout", ",", "hc", ".", "Mark", ")", "\n", "if", "err", "!=", "nil", "{", "msg", "=", "fmt", ".", "Sprintf", "(", "\"%s; failed to create socket\"", ",", "msg", ")", "\n", "return", "complete", "(", "start", ",", "msg", ",", "false", ",", "err", ")", "\n", "}", "\n", "defer", "conn", ".", "Close", "(", ")", "\n", "err", "=", "conn", ".", "SetDeadline", "(", "deadline", ")", "\n", "if", "err", "!=", "nil", "{", "msg", "=", "fmt", ".", "Sprintf", "(", "\"%s; failed to set deadline\"", ",", "msg", ")", "\n", "return", "complete", "(", "start", ",", "msg", ",", "false", ",", "err", ")", "\n", "}", "\n", "if", "_", ",", "err", "=", "conn", ".", "Write", "(", "[", "]", "byte", "(", "hc", ".", "Send", ")", ")", ";", "err", "!=", "nil", "{", "msg", "=", "fmt", ".", "Sprintf", "(", "\"%s; failed to send request\"", ",", "msg", ")", "\n", "return", "complete", "(", "start", ",", "msg", ",", "false", ",", "err", ")", "\n", "}", "\n", "buf", ":=", "make", "(", "[", "]", "byte", ",", "len", "(", "hc", ".", "Receive", ")", ")", "\n", "n", ",", "_", ",", "err", ":=", "conn", ".", "ReadFrom", "(", "buf", ")", "\n", "if", "err", "!=", "nil", "{", "msg", "=", "fmt", ".", "Sprintf", "(", "\"%s; failed to read response\"", ",", "msg", ")", "\n", "return", "complete", "(", "start", ",", "msg", ",", "false", ",", "err", ")", "\n", "}", "\n", "got", ":=", "string", "(", "buf", "[", "0", ":", "n", "]", ")", "\n", "if", "got", "!=", "hc", ".", "Receive", "{", "msg", "=", "fmt", ".", "Sprintf", "(", "\"%s; unexpected response - %q\"", ",", "msg", ",", "got", ")", "\n", "return", "complete", "(", "start", ",", "msg", ",", "false", ",", "err", ")", "\n", "}", "\n", "return", "complete", "(", "start", ",", "msg", ",", "true", ",", "err", ")", "\n", "}" ]
// 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", ",", "err", ":=", "cfg", ".", "GetString", "(", "section", ",", "option", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Exitf", "(", "\"Failed to get %s for %s: %v\"", ",", "option", ",", "section", ",", "err", ")", "\n", "}", "\n", "return", "s", "\n", "}" ]
// 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", "==", "\"\"", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "ip", ":=", "net", ".", "ParseIP", "(", "ipStr", ")", "\n", "if", "ip", "==", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"%s: %q is not a valid IP address\"", ",", "option", ",", "ipStr", ")", "\n", "}", "\n", "return", "ip", ",", "nil", "\n", "}" ]
// 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", "\n", "err", ":=", "r", ".", "conn", ".", "Close", "(", ")", "\n", "r", ".", "Unlock", "(", ")", "\n", "return", "err", "\n", "}" ]
// 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", "return", "idx", ",", "err", "\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", "return", "idx", ",", "err", "\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 { err = r.decodeRaftLog(val, log) } tx.Rollback() r.RUnlock() return err }
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 { err = r.decodeRaftLog(val, log) } tx.Rollback() r.RUnlock() return err }
[ "func", "(", "r", "*", "raftLog", ")", "GetLog", "(", "idx", "uint64", ",", "log", "*", "raft", ".", "Log", ")", "error", "{", "r", ".", "RLock", "(", ")", "\n", "tx", ",", "err", ":=", "r", ".", "conn", ".", "Begin", "(", "false", ")", "\n", "if", "err", "!=", "nil", "{", "r", ".", "RUnlock", "(", ")", "\n", "return", "err", "\n", "}", "\n", "var", "key", "[", "8", "]", "byte", "\n", "binary", ".", "BigEndian", ".", "PutUint64", "(", "key", "[", ":", "]", ",", "idx", ")", "\n", "bucket", ":=", "tx", ".", "Bucket", "(", "logsBucket", ")", "\n", "val", ":=", "bucket", ".", "Get", "(", "key", "[", ":", "]", ")", "\n", "if", "val", "==", "nil", "{", "err", "=", "raft", ".", "ErrLogNotFound", "\n", "}", "else", "{", "err", "=", "r", ".", "decodeRaftLog", "(", "val", ",", "log", ")", "\n", "}", "\n", "tx", ".", "Rollback", "(", ")", "\n", "r", ".", "RUnlock", "(", ")", "\n", "return", "err", "\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