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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
guregu/null | bool.go | UnmarshalJSON | func (b *Bool) UnmarshalJSON(data []byte) error {
var err error
var v interface{}
if err = json.Unmarshal(data, &v); err != nil {
return err
}
switch x := v.(type) {
case bool:
b.Bool = x
case map[string]interface{}:
err = json.Unmarshal(data, &b.NullBool)
case nil:
b.Valid = false
return nil
default... | go | func (b *Bool) UnmarshalJSON(data []byte) error {
var err error
var v interface{}
if err = json.Unmarshal(data, &v); err != nil {
return err
}
switch x := v.(type) {
case bool:
b.Bool = x
case map[string]interface{}:
err = json.Unmarshal(data, &b.NullBool)
case nil:
b.Valid = false
return nil
default... | [
"func",
"(",
"b",
"*",
"Bool",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"var",
"v",
"interface",
"{",
"}",
"\n",
"if",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"v",
... | // UnmarshalJSON implements json.Unmarshaler.
// It supports number and null input.
// 0 will not be considered a null Bool.
// It also supports unmarshalling a sql.NullBool. | [
"UnmarshalJSON",
"implements",
"json",
".",
"Unmarshaler",
".",
"It",
"supports",
"number",
"and",
"null",
"input",
".",
"0",
"will",
"not",
"be",
"considered",
"a",
"null",
"Bool",
".",
"It",
"also",
"supports",
"unmarshalling",
"a",
"sql",
".",
"NullBool",... | 80515d440932108546bcade467bb7d6968e812e2 | https://github.com/guregu/null/blob/80515d440932108546bcade467bb7d6968e812e2/bool.go#L50-L69 | test |
guregu/null | bool.go | UnmarshalText | func (b *Bool) UnmarshalText(text []byte) error {
str := string(text)
switch str {
case "", "null":
b.Valid = false
return nil
case "true":
b.Bool = true
case "false":
b.Bool = false
default:
b.Valid = false
return errors.New("invalid input:" + str)
}
b.Valid = true
return nil
} | go | func (b *Bool) UnmarshalText(text []byte) error {
str := string(text)
switch str {
case "", "null":
b.Valid = false
return nil
case "true":
b.Bool = true
case "false":
b.Bool = false
default:
b.Valid = false
return errors.New("invalid input:" + str)
}
b.Valid = true
return nil
} | [
"func",
"(",
"b",
"*",
"Bool",
")",
"UnmarshalText",
"(",
"text",
"[",
"]",
"byte",
")",
"error",
"{",
"str",
":=",
"string",
"(",
"text",
")",
"\n",
"switch",
"str",
"{",
"case",
"\"\"",
",",
"\"null\"",
":",
"b",
".",
"Valid",
"=",
"false",
"\n... | // UnmarshalText implements encoding.TextUnmarshaler.
// It will unmarshal to a null Bool if the input is a blank or not an integer.
// It will return an error if the input is not an integer, blank, or "null". | [
"UnmarshalText",
"implements",
"encoding",
".",
"TextUnmarshaler",
".",
"It",
"will",
"unmarshal",
"to",
"a",
"null",
"Bool",
"if",
"the",
"input",
"is",
"a",
"blank",
"or",
"not",
"an",
"integer",
".",
"It",
"will",
"return",
"an",
"error",
"if",
"the",
... | 80515d440932108546bcade467bb7d6968e812e2 | https://github.com/guregu/null/blob/80515d440932108546bcade467bb7d6968e812e2/bool.go#L74-L90 | test |
guregu/null | bool.go | MarshalJSON | func (b Bool) MarshalJSON() ([]byte, error) {
if !b.Valid {
return []byte("null"), nil
}
if !b.Bool {
return []byte("false"), nil
}
return []byte("true"), nil
} | go | func (b Bool) MarshalJSON() ([]byte, error) {
if !b.Valid {
return []byte("null"), nil
}
if !b.Bool {
return []byte("false"), nil
}
return []byte("true"), nil
} | [
"func",
"(",
"b",
"Bool",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"!",
"b",
".",
"Valid",
"{",
"return",
"[",
"]",
"byte",
"(",
"\"null\"",
")",
",",
"nil",
"\n",
"}",
"\n",
"if",
"!",
"b",
".",
"B... | // MarshalJSON implements json.Marshaler.
// It will encode null if this Bool is null. | [
"MarshalJSON",
"implements",
"json",
".",
"Marshaler",
".",
"It",
"will",
"encode",
"null",
"if",
"this",
"Bool",
"is",
"null",
"."
] | 80515d440932108546bcade467bb7d6968e812e2 | https://github.com/guregu/null/blob/80515d440932108546bcade467bb7d6968e812e2/bool.go#L94-L102 | test |
guregu/null | bool.go | SetValid | func (b *Bool) SetValid(v bool) {
b.Bool = v
b.Valid = true
} | go | func (b *Bool) SetValid(v bool) {
b.Bool = v
b.Valid = true
} | [
"func",
"(",
"b",
"*",
"Bool",
")",
"SetValid",
"(",
"v",
"bool",
")",
"{",
"b",
".",
"Bool",
"=",
"v",
"\n",
"b",
".",
"Valid",
"=",
"true",
"\n",
"}"
] | // SetValid changes this Bool's value and also sets it to be non-null. | [
"SetValid",
"changes",
"this",
"Bool",
"s",
"value",
"and",
"also",
"sets",
"it",
"to",
"be",
"non",
"-",
"null",
"."
] | 80515d440932108546bcade467bb7d6968e812e2 | https://github.com/guregu/null/blob/80515d440932108546bcade467bb7d6968e812e2/bool.go#L117-L120 | test |
guregu/null | zero/string.go | NewString | func NewString(s string, valid bool) String {
return String{
NullString: sql.NullString{
String: s,
Valid: valid,
},
}
} | go | func NewString(s string, valid bool) String {
return String{
NullString: sql.NullString{
String: s,
Valid: valid,
},
}
} | [
"func",
"NewString",
"(",
"s",
"string",
",",
"valid",
"bool",
")",
"String",
"{",
"return",
"String",
"{",
"NullString",
":",
"sql",
".",
"NullString",
"{",
"String",
":",
"s",
",",
"Valid",
":",
"valid",
",",
"}",
",",
"}",
"\n",
"}"
] | // NewString creates a new String | [
"NewString",
"creates",
"a",
"new",
"String"
] | 80515d440932108546bcade467bb7d6968e812e2 | https://github.com/guregu/null/blob/80515d440932108546bcade467bb7d6968e812e2/zero/string.go#L22-L29 | test |
guregu/null | zero/string.go | UnmarshalJSON | func (s *String) UnmarshalJSON(data []byte) error {
var err error
var v interface{}
if err = json.Unmarshal(data, &v); err != nil {
return err
}
switch x := v.(type) {
case string:
s.String = x
case map[string]interface{}:
err = json.Unmarshal(data, &s.NullString)
case nil:
s.Valid = false
return nil
... | go | func (s *String) UnmarshalJSON(data []byte) error {
var err error
var v interface{}
if err = json.Unmarshal(data, &v); err != nil {
return err
}
switch x := v.(type) {
case string:
s.String = x
case map[string]interface{}:
err = json.Unmarshal(data, &s.NullString)
case nil:
s.Valid = false
return nil
... | [
"func",
"(",
"s",
"*",
"String",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"var",
"v",
"interface",
"{",
"}",
"\n",
"if",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"v",... | // UnmarshalJSON implements json.Unmarshaler.
// It supports string and null input. Blank string input produces a null String.
// It also supports unmarshalling a sql.NullString. | [
"UnmarshalJSON",
"implements",
"json",
".",
"Unmarshaler",
".",
"It",
"supports",
"string",
"and",
"null",
"input",
".",
"Blank",
"string",
"input",
"produces",
"a",
"null",
"String",
".",
"It",
"also",
"supports",
"unmarshalling",
"a",
"sql",
".",
"NullString... | 80515d440932108546bcade467bb7d6968e812e2 | https://github.com/guregu/null/blob/80515d440932108546bcade467bb7d6968e812e2/zero/string.go#L48-L67 | test |
guregu/null | zero/string.go | MarshalText | func (s String) MarshalText() ([]byte, error) {
if !s.Valid {
return []byte{}, nil
}
return []byte(s.String), nil
} | go | func (s String) MarshalText() ([]byte, error) {
if !s.Valid {
return []byte{}, nil
}
return []byte(s.String), nil
} | [
"func",
"(",
"s",
"String",
")",
"MarshalText",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"!",
"s",
".",
"Valid",
"{",
"return",
"[",
"]",
"byte",
"{",
"}",
",",
"nil",
"\n",
"}",
"\n",
"return",
"[",
"]",
"byte",
"(",
... | // MarshalText implements encoding.TextMarshaler.
// It will encode a blank string when this String is null. | [
"MarshalText",
"implements",
"encoding",
".",
"TextMarshaler",
".",
"It",
"will",
"encode",
"a",
"blank",
"string",
"when",
"this",
"String",
"is",
"null",
"."
] | 80515d440932108546bcade467bb7d6968e812e2 | https://github.com/guregu/null/blob/80515d440932108546bcade467bb7d6968e812e2/zero/string.go#L71-L76 | test |
guregu/null | zero/string.go | UnmarshalText | func (s *String) UnmarshalText(text []byte) error {
s.String = string(text)
s.Valid = s.String != ""
return nil
} | go | func (s *String) UnmarshalText(text []byte) error {
s.String = string(text)
s.Valid = s.String != ""
return nil
} | [
"func",
"(",
"s",
"*",
"String",
")",
"UnmarshalText",
"(",
"text",
"[",
"]",
"byte",
")",
"error",
"{",
"s",
".",
"String",
"=",
"string",
"(",
"text",
")",
"\n",
"s",
".",
"Valid",
"=",
"s",
".",
"String",
"!=",
"\"\"",
"\n",
"return",
"nil",
... | // UnmarshalText implements encoding.TextUnmarshaler.
// It will unmarshal to a null String if the input is a blank string. | [
"UnmarshalText",
"implements",
"encoding",
".",
"TextUnmarshaler",
".",
"It",
"will",
"unmarshal",
"to",
"a",
"null",
"String",
"if",
"the",
"input",
"is",
"a",
"blank",
"string",
"."
] | 80515d440932108546bcade467bb7d6968e812e2 | https://github.com/guregu/null/blob/80515d440932108546bcade467bb7d6968e812e2/zero/string.go#L80-L84 | test |
guregu/null | zero/string.go | SetValid | func (s *String) SetValid(v string) {
s.String = v
s.Valid = true
} | go | func (s *String) SetValid(v string) {
s.String = v
s.Valid = true
} | [
"func",
"(",
"s",
"*",
"String",
")",
"SetValid",
"(",
"v",
"string",
")",
"{",
"s",
".",
"String",
"=",
"v",
"\n",
"s",
".",
"Valid",
"=",
"true",
"\n",
"}"
] | // SetValid changes this String's value and also sets it to be non-null. | [
"SetValid",
"changes",
"this",
"String",
"s",
"value",
"and",
"also",
"sets",
"it",
"to",
"be",
"non",
"-",
"null",
"."
] | 80515d440932108546bcade467bb7d6968e812e2 | https://github.com/guregu/null/blob/80515d440932108546bcade467bb7d6968e812e2/zero/string.go#L87-L90 | test |
guregu/null | string.go | StringFromPtr | func StringFromPtr(s *string) String {
if s == nil {
return NewString("", false)
}
return NewString(*s, true)
} | go | func StringFromPtr(s *string) String {
if s == nil {
return NewString("", false)
}
return NewString(*s, true)
} | [
"func",
"StringFromPtr",
"(",
"s",
"*",
"string",
")",
"String",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"NewString",
"(",
"\"\"",
",",
"false",
")",
"\n",
"}",
"\n",
"return",
"NewString",
"(",
"*",
"s",
",",
"true",
")",
"\n",
"}"
] | // StringFromPtr creates a new String that be null if s is nil. | [
"StringFromPtr",
"creates",
"a",
"new",
"String",
"that",
"be",
"null",
"if",
"s",
"is",
"nil",
"."
] | 80515d440932108546bcade467bb7d6968e812e2 | https://github.com/guregu/null/blob/80515d440932108546bcade467bb7d6968e812e2/string.go#L26-L31 | test |
guregu/null | string.go | MarshalJSON | func (s String) MarshalJSON() ([]byte, error) {
if !s.Valid {
return []byte("null"), nil
}
return json.Marshal(s.String)
} | go | func (s String) MarshalJSON() ([]byte, error) {
if !s.Valid {
return []byte("null"), nil
}
return json.Marshal(s.String)
} | [
"func",
"(",
"s",
"String",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"!",
"s",
".",
"Valid",
"{",
"return",
"[",
"]",
"byte",
"(",
"\"null\"",
")",
",",
"nil",
"\n",
"}",
"\n",
"return",
"json",
".",
... | // MarshalJSON implements json.Marshaler.
// It will encode null if this String is null. | [
"MarshalJSON",
"implements",
"json",
".",
"Marshaler",
".",
"It",
"will",
"encode",
"null",
"if",
"this",
"String",
"is",
"null",
"."
] | 80515d440932108546bcade467bb7d6968e812e2 | https://github.com/guregu/null/blob/80515d440932108546bcade467bb7d6968e812e2/string.go#L77-L82 | test |
guregu/null | zero/int.go | NewInt | func NewInt(i int64, valid bool) Int {
return Int{
NullInt64: sql.NullInt64{
Int64: i,
Valid: valid,
},
}
} | go | func NewInt(i int64, valid bool) Int {
return Int{
NullInt64: sql.NullInt64{
Int64: i,
Valid: valid,
},
}
} | [
"func",
"NewInt",
"(",
"i",
"int64",
",",
"valid",
"bool",
")",
"Int",
"{",
"return",
"Int",
"{",
"NullInt64",
":",
"sql",
".",
"NullInt64",
"{",
"Int64",
":",
"i",
",",
"Valid",
":",
"valid",
",",
"}",
",",
"}",
"\n",
"}"
] | // NewInt creates a new Int | [
"NewInt",
"creates",
"a",
"new",
"Int"
] | 80515d440932108546bcade467bb7d6968e812e2 | https://github.com/guregu/null/blob/80515d440932108546bcade467bb7d6968e812e2/zero/int.go#L19-L26 | test |
guregu/null | zero/int.go | IntFromPtr | func IntFromPtr(i *int64) Int {
if i == nil {
return NewInt(0, false)
}
n := NewInt(*i, true)
return n
} | go | func IntFromPtr(i *int64) Int {
if i == nil {
return NewInt(0, false)
}
n := NewInt(*i, true)
return n
} | [
"func",
"IntFromPtr",
"(",
"i",
"*",
"int64",
")",
"Int",
"{",
"if",
"i",
"==",
"nil",
"{",
"return",
"NewInt",
"(",
"0",
",",
"false",
")",
"\n",
"}",
"\n",
"n",
":=",
"NewInt",
"(",
"*",
"i",
",",
"true",
")",
"\n",
"return",
"n",
"\n",
"}"... | // IntFromPtr creates a new Int that be null if i is nil. | [
"IntFromPtr",
"creates",
"a",
"new",
"Int",
"that",
"be",
"null",
"if",
"i",
"is",
"nil",
"."
] | 80515d440932108546bcade467bb7d6968e812e2 | https://github.com/guregu/null/blob/80515d440932108546bcade467bb7d6968e812e2/zero/int.go#L34-L40 | test |
guregu/null | zero/int.go | UnmarshalJSON | func (i *Int) UnmarshalJSON(data []byte) error {
var err error
var v interface{}
if err = json.Unmarshal(data, &v); err != nil {
return err
}
switch x := v.(type) {
case float64:
// Unmarshal again, directly to int64, to avoid intermediate float64
err = json.Unmarshal(data, &i.Int64)
case string:
str := ... | go | func (i *Int) UnmarshalJSON(data []byte) error {
var err error
var v interface{}
if err = json.Unmarshal(data, &v); err != nil {
return err
}
switch x := v.(type) {
case float64:
// Unmarshal again, directly to int64, to avoid intermediate float64
err = json.Unmarshal(data, &i.Int64)
case string:
str := ... | [
"func",
"(",
"i",
"*",
"Int",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"var",
"v",
"interface",
"{",
"}",
"\n",
"if",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"v",
... | // UnmarshalJSON implements json.Unmarshaler.
// It supports number and null input.
// 0 will be considered a null Int.
// It also supports unmarshalling a sql.NullInt64. | [
"UnmarshalJSON",
"implements",
"json",
".",
"Unmarshaler",
".",
"It",
"supports",
"number",
"and",
"null",
"input",
".",
"0",
"will",
"be",
"considered",
"a",
"null",
"Int",
".",
"It",
"also",
"supports",
"unmarshalling",
"a",
"sql",
".",
"NullInt64",
"."
] | 80515d440932108546bcade467bb7d6968e812e2 | https://github.com/guregu/null/blob/80515d440932108546bcade467bb7d6968e812e2/zero/int.go#L46-L73 | test |
guregu/null | zero/int.go | MarshalText | func (i Int) MarshalText() ([]byte, error) {
n := i.Int64
if !i.Valid {
n = 0
}
return []byte(strconv.FormatInt(n, 10)), nil
} | go | func (i Int) MarshalText() ([]byte, error) {
n := i.Int64
if !i.Valid {
n = 0
}
return []byte(strconv.FormatInt(n, 10)), nil
} | [
"func",
"(",
"i",
"Int",
")",
"MarshalText",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"n",
":=",
"i",
".",
"Int64",
"\n",
"if",
"!",
"i",
".",
"Valid",
"{",
"n",
"=",
"0",
"\n",
"}",
"\n",
"return",
"[",
"]",
"byte",
"(",
... | // MarshalText implements encoding.TextMarshaler.
// It will encode a zero if this Int is null. | [
"MarshalText",
"implements",
"encoding",
".",
"TextMarshaler",
".",
"It",
"will",
"encode",
"a",
"zero",
"if",
"this",
"Int",
"is",
"null",
"."
] | 80515d440932108546bcade467bb7d6968e812e2 | https://github.com/guregu/null/blob/80515d440932108546bcade467bb7d6968e812e2/zero/int.go#L102-L108 | test |
guregu/null | zero/int.go | SetValid | func (i *Int) SetValid(n int64) {
i.Int64 = n
i.Valid = true
} | go | func (i *Int) SetValid(n int64) {
i.Int64 = n
i.Valid = true
} | [
"func",
"(",
"i",
"*",
"Int",
")",
"SetValid",
"(",
"n",
"int64",
")",
"{",
"i",
".",
"Int64",
"=",
"n",
"\n",
"i",
".",
"Valid",
"=",
"true",
"\n",
"}"
] | // SetValid changes this Int's value and also sets it to be non-null. | [
"SetValid",
"changes",
"this",
"Int",
"s",
"value",
"and",
"also",
"sets",
"it",
"to",
"be",
"non",
"-",
"null",
"."
] | 80515d440932108546bcade467bb7d6968e812e2 | https://github.com/guregu/null/blob/80515d440932108546bcade467bb7d6968e812e2/zero/int.go#L111-L114 | test |
guregu/null | int.go | UnmarshalText | func (i *Int) UnmarshalText(text []byte) error {
str := string(text)
if str == "" || str == "null" {
i.Valid = false
return nil
}
var err error
i.Int64, err = strconv.ParseInt(string(text), 10, 64)
i.Valid = err == nil
return err
} | go | func (i *Int) UnmarshalText(text []byte) error {
str := string(text)
if str == "" || str == "null" {
i.Valid = false
return nil
}
var err error
i.Int64, err = strconv.ParseInt(string(text), 10, 64)
i.Valid = err == nil
return err
} | [
"func",
"(",
"i",
"*",
"Int",
")",
"UnmarshalText",
"(",
"text",
"[",
"]",
"byte",
")",
"error",
"{",
"str",
":=",
"string",
"(",
"text",
")",
"\n",
"if",
"str",
"==",
"\"\"",
"||",
"str",
"==",
"\"null\"",
"{",
"i",
".",
"Valid",
"=",
"false",
... | // UnmarshalText implements encoding.TextUnmarshaler.
// It will unmarshal to a null Int if the input is a blank or not an integer.
// It will return an error if the input is not an integer, blank, or "null". | [
"UnmarshalText",
"implements",
"encoding",
".",
"TextUnmarshaler",
".",
"It",
"will",
"unmarshal",
"to",
"a",
"null",
"Int",
"if",
"the",
"input",
"is",
"a",
"blank",
"or",
"not",
"an",
"integer",
".",
"It",
"will",
"return",
"an",
"error",
"if",
"the",
... | 80515d440932108546bcade467bb7d6968e812e2 | https://github.com/guregu/null/blob/80515d440932108546bcade467bb7d6968e812e2/int.go#L85-L95 | test |
guregu/null | zero/bool.go | MarshalText | func (b Bool) MarshalText() ([]byte, error) {
if !b.Valid || !b.Bool {
return []byte("false"), nil
}
return []byte("true"), nil
} | go | func (b Bool) MarshalText() ([]byte, error) {
if !b.Valid || !b.Bool {
return []byte("false"), nil
}
return []byte("true"), nil
} | [
"func",
"(",
"b",
"Bool",
")",
"MarshalText",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"!",
"b",
".",
"Valid",
"||",
"!",
"b",
".",
"Bool",
"{",
"return",
"[",
"]",
"byte",
"(",
"\"false\"",
")",
",",
"nil",
"\n",
"}",
... | // MarshalText implements encoding.TextMarshaler.
// It will encode a zero if this Bool is null. | [
"MarshalText",
"implements",
"encoding",
".",
"TextMarshaler",
".",
"It",
"will",
"encode",
"a",
"zero",
"if",
"this",
"Bool",
"is",
"null",
"."
] | 80515d440932108546bcade467bb7d6968e812e2 | https://github.com/guregu/null/blob/80515d440932108546bcade467bb7d6968e812e2/zero/bool.go#L97-L102 | test |
guregu/null | zero/float.go | SetValid | func (f *Float) SetValid(v float64) {
f.Float64 = v
f.Valid = true
} | go | func (f *Float) SetValid(v float64) {
f.Float64 = v
f.Valid = true
} | [
"func",
"(",
"f",
"*",
"Float",
")",
"SetValid",
"(",
"v",
"float64",
")",
"{",
"f",
".",
"Float64",
"=",
"v",
"\n",
"f",
".",
"Valid",
"=",
"true",
"\n",
"}"
] | // SetValid changes this Float's value and also sets it to be non-null. | [
"SetValid",
"changes",
"this",
"Float",
"s",
"value",
"and",
"also",
"sets",
"it",
"to",
"be",
"non",
"-",
"null",
"."
] | 80515d440932108546bcade467bb7d6968e812e2 | https://github.com/guregu/null/blob/80515d440932108546bcade467bb7d6968e812e2/zero/float.go#L116-L119 | test |
guregu/null | zero/time.go | MarshalJSON | func (t Time) MarshalJSON() ([]byte, error) {
if !t.Valid {
return (time.Time{}).MarshalJSON()
}
return t.Time.MarshalJSON()
} | go | func (t Time) MarshalJSON() ([]byte, error) {
if !t.Valid {
return (time.Time{}).MarshalJSON()
}
return t.Time.MarshalJSON()
} | [
"func",
"(",
"t",
"Time",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"!",
"t",
".",
"Valid",
"{",
"return",
"(",
"time",
".",
"Time",
"{",
"}",
")",
".",
"MarshalJSON",
"(",
")",
"\n",
"}",
"\n",
"retur... | // MarshalJSON implements json.Marshaler.
// It will encode the zero value of time.Time
// if this time is invalid. | [
"MarshalJSON",
"implements",
"json",
".",
"Marshaler",
".",
"It",
"will",
"encode",
"the",
"zero",
"value",
"of",
"time",
".",
"Time",
"if",
"this",
"time",
"is",
"invalid",
"."
] | 80515d440932108546bcade467bb7d6968e812e2 | https://github.com/guregu/null/blob/80515d440932108546bcade467bb7d6968e812e2/zero/time.go#L69-L74 | test |
guregu/null | float.go | UnmarshalJSON | func (f *Float) UnmarshalJSON(data []byte) error {
var err error
var v interface{}
if err = json.Unmarshal(data, &v); err != nil {
return err
}
switch x := v.(type) {
case float64:
f.Float64 = float64(x)
case string:
str := string(x)
if len(str) == 0 {
f.Valid = false
return nil
}
f.Float64, er... | go | func (f *Float) UnmarshalJSON(data []byte) error {
var err error
var v interface{}
if err = json.Unmarshal(data, &v); err != nil {
return err
}
switch x := v.(type) {
case float64:
f.Float64 = float64(x)
case string:
str := string(x)
if len(str) == 0 {
f.Valid = false
return nil
}
f.Float64, er... | [
"func",
"(",
"f",
"*",
"Float",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"var",
"v",
"interface",
"{",
"}",
"\n",
"if",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"v",
... | // UnmarshalJSON implements json.Unmarshaler.
// It supports number and null input.
// 0 will not be considered a null Float.
// It also supports unmarshalling a sql.NullFloat64. | [
"UnmarshalJSON",
"implements",
"json",
".",
"Unmarshaler",
".",
"It",
"supports",
"number",
"and",
"null",
"input",
".",
"0",
"will",
"not",
"be",
"considered",
"a",
"null",
"Float",
".",
"It",
"also",
"supports",
"unmarshalling",
"a",
"sql",
".",
"NullFloat... | 80515d440932108546bcade467bb7d6968e812e2 | https://github.com/guregu/null/blob/80515d440932108546bcade467bb7d6968e812e2/float.go#L54-L80 | test |
guregu/null | float.go | UnmarshalText | func (f *Float) UnmarshalText(text []byte) error {
str := string(text)
if str == "" || str == "null" {
f.Valid = false
return nil
}
var err error
f.Float64, err = strconv.ParseFloat(string(text), 64)
f.Valid = err == nil
return err
} | go | func (f *Float) UnmarshalText(text []byte) error {
str := string(text)
if str == "" || str == "null" {
f.Valid = false
return nil
}
var err error
f.Float64, err = strconv.ParseFloat(string(text), 64)
f.Valid = err == nil
return err
} | [
"func",
"(",
"f",
"*",
"Float",
")",
"UnmarshalText",
"(",
"text",
"[",
"]",
"byte",
")",
"error",
"{",
"str",
":=",
"string",
"(",
"text",
")",
"\n",
"if",
"str",
"==",
"\"\"",
"||",
"str",
"==",
"\"null\"",
"{",
"f",
".",
"Valid",
"=",
"false",... | // UnmarshalText implements encoding.TextUnmarshaler.
// It will unmarshal to a null Float if the input is a blank or not an integer.
// It will return an error if the input is not an integer, blank, or "null". | [
"UnmarshalText",
"implements",
"encoding",
".",
"TextUnmarshaler",
".",
"It",
"will",
"unmarshal",
"to",
"a",
"null",
"Float",
"if",
"the",
"input",
"is",
"a",
"blank",
"or",
"not",
"an",
"integer",
".",
"It",
"will",
"return",
"an",
"error",
"if",
"the",
... | 80515d440932108546bcade467bb7d6968e812e2 | https://github.com/guregu/null/blob/80515d440932108546bcade467bb7d6968e812e2/float.go#L85-L95 | test |
guregu/null | float.go | MarshalJSON | func (f Float) MarshalJSON() ([]byte, error) {
if !f.Valid {
return []byte("null"), nil
}
if math.IsInf(f.Float64, 0) || math.IsNaN(f.Float64) {
return nil, &json.UnsupportedValueError{
Value: reflect.ValueOf(f.Float64),
Str: strconv.FormatFloat(f.Float64, 'g', -1, 64),
}
}
return []byte(strconv.Form... | go | func (f Float) MarshalJSON() ([]byte, error) {
if !f.Valid {
return []byte("null"), nil
}
if math.IsInf(f.Float64, 0) || math.IsNaN(f.Float64) {
return nil, &json.UnsupportedValueError{
Value: reflect.ValueOf(f.Float64),
Str: strconv.FormatFloat(f.Float64, 'g', -1, 64),
}
}
return []byte(strconv.Form... | [
"func",
"(",
"f",
"Float",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"!",
"f",
".",
"Valid",
"{",
"return",
"[",
"]",
"byte",
"(",
"\"null\"",
")",
",",
"nil",
"\n",
"}",
"\n",
"if",
"math",
".",
"IsIn... | // MarshalJSON implements json.Marshaler.
// It will encode null if this Float is null. | [
"MarshalJSON",
"implements",
"json",
".",
"Marshaler",
".",
"It",
"will",
"encode",
"null",
"if",
"this",
"Float",
"is",
"null",
"."
] | 80515d440932108546bcade467bb7d6968e812e2 | https://github.com/guregu/null/blob/80515d440932108546bcade467bb7d6968e812e2/float.go#L99-L110 | test |
weaveworks/mesh | gossip_channel.go | newGossipChannel | func newGossipChannel(channelName string, ourself *localPeer, r *routes, g Gossiper, logger Logger) *gossipChannel {
return &gossipChannel{
name: channelName,
ourself: ourself,
routes: r,
gossiper: g,
logger: logger,
}
} | go | func newGossipChannel(channelName string, ourself *localPeer, r *routes, g Gossiper, logger Logger) *gossipChannel {
return &gossipChannel{
name: channelName,
ourself: ourself,
routes: r,
gossiper: g,
logger: logger,
}
} | [
"func",
"newGossipChannel",
"(",
"channelName",
"string",
",",
"ourself",
"*",
"localPeer",
",",
"r",
"*",
"routes",
",",
"g",
"Gossiper",
",",
"logger",
"Logger",
")",
"*",
"gossipChannel",
"{",
"return",
"&",
"gossipChannel",
"{",
"name",
":",
"channelName... | // newGossipChannel returns a named, usable channel.
// It delegates receiving duties to the passed Gossiper. | [
"newGossipChannel",
"returns",
"a",
"named",
"usable",
"channel",
".",
"It",
"delegates",
"receiving",
"duties",
"to",
"the",
"passed",
"Gossiper",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/gossip_channel.go#L20-L28 | test |
weaveworks/mesh | gossip_channel.go | GossipUnicast | func (c *gossipChannel) GossipUnicast(dstPeerName PeerName, msg []byte) error {
return c.relayUnicast(dstPeerName, gobEncode(c.name, c.ourself.Name, dstPeerName, msg))
} | go | func (c *gossipChannel) GossipUnicast(dstPeerName PeerName, msg []byte) error {
return c.relayUnicast(dstPeerName, gobEncode(c.name, c.ourself.Name, dstPeerName, msg))
} | [
"func",
"(",
"c",
"*",
"gossipChannel",
")",
"GossipUnicast",
"(",
"dstPeerName",
"PeerName",
",",
"msg",
"[",
"]",
"byte",
")",
"error",
"{",
"return",
"c",
".",
"relayUnicast",
"(",
"dstPeerName",
",",
"gobEncode",
"(",
"c",
".",
"name",
",",
"c",
".... | // GossipUnicast implements Gossip, relaying msg to dst, which must be a
// member of the channel. | [
"GossipUnicast",
"implements",
"Gossip",
"relaying",
"msg",
"to",
"dst",
"which",
"must",
"be",
"a",
"member",
"of",
"the",
"channel",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/gossip_channel.go#L76-L78 | test |
weaveworks/mesh | gossip_channel.go | GossipBroadcast | func (c *gossipChannel) GossipBroadcast(update GossipData) {
c.relayBroadcast(c.ourself.Name, update)
} | go | func (c *gossipChannel) GossipBroadcast(update GossipData) {
c.relayBroadcast(c.ourself.Name, update)
} | [
"func",
"(",
"c",
"*",
"gossipChannel",
")",
"GossipBroadcast",
"(",
"update",
"GossipData",
")",
"{",
"c",
".",
"relayBroadcast",
"(",
"c",
".",
"ourself",
".",
"Name",
",",
"update",
")",
"\n",
"}"
] | // GossipBroadcast implements Gossip, relaying update to all members of the
// channel. | [
"GossipBroadcast",
"implements",
"Gossip",
"relaying",
"update",
"to",
"all",
"members",
"of",
"the",
"channel",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/gossip_channel.go#L82-L84 | test |
weaveworks/mesh | gossip_channel.go | Send | func (c *gossipChannel) Send(data GossipData) {
c.relay(c.ourself.Name, data)
} | go | func (c *gossipChannel) Send(data GossipData) {
c.relay(c.ourself.Name, data)
} | [
"func",
"(",
"c",
"*",
"gossipChannel",
")",
"Send",
"(",
"data",
"GossipData",
")",
"{",
"c",
".",
"relay",
"(",
"c",
".",
"ourself",
".",
"Name",
",",
"data",
")",
"\n",
"}"
] | // Send relays data into the channel topology via random neighbours. | [
"Send",
"relays",
"data",
"into",
"the",
"channel",
"topology",
"via",
"random",
"neighbours",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/gossip_channel.go#L87-L89 | test |
weaveworks/mesh | gossip_channel.go | SendDown | func (c *gossipChannel) SendDown(conn Connection, data GossipData) {
c.senderFor(conn).Send(data)
} | go | func (c *gossipChannel) SendDown(conn Connection, data GossipData) {
c.senderFor(conn).Send(data)
} | [
"func",
"(",
"c",
"*",
"gossipChannel",
")",
"SendDown",
"(",
"conn",
"Connection",
",",
"data",
"GossipData",
")",
"{",
"c",
".",
"senderFor",
"(",
"conn",
")",
".",
"Send",
"(",
"data",
")",
"\n",
"}"
] | // SendDown relays data into the channel topology via conn. | [
"SendDown",
"relays",
"data",
"into",
"the",
"channel",
"topology",
"via",
"conn",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/gossip_channel.go#L92-L94 | test |
weaveworks/mesh | gossip_channel.go | gobEncode | func gobEncode(items ...interface{}) []byte {
buf := new(bytes.Buffer)
enc := gob.NewEncoder(buf)
for _, i := range items {
if err := enc.Encode(i); err != nil {
panic(err)
}
}
return buf.Bytes()
} | go | func gobEncode(items ...interface{}) []byte {
buf := new(bytes.Buffer)
enc := gob.NewEncoder(buf)
for _, i := range items {
if err := enc.Encode(i); err != nil {
panic(err)
}
}
return buf.Bytes()
} | [
"func",
"gobEncode",
"(",
"items",
"...",
"interface",
"{",
"}",
")",
"[",
"]",
"byte",
"{",
"buf",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"enc",
":=",
"gob",
".",
"NewEncoder",
"(",
"buf",
")",
"\n",
"for",
"_",
",",
"i",
":=",
"... | // GobEncode gob-encodes each item and returns the resulting byte slice. | [
"GobEncode",
"gob",
"-",
"encodes",
"each",
"item",
"and",
"returns",
"the",
"resulting",
"byte",
"slice",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/gossip_channel.go#L143-L152 | test |
weaveworks/mesh | token_bucket.go | newTokenBucket | func newTokenBucket(capacity int64, tokenInterval time.Duration) *tokenBucket {
tb := tokenBucket{
capacity: capacity,
tokenInterval: tokenInterval,
refillDuration: tokenInterval * time.Duration(capacity)}
tb.earliestUnspentToken = tb.capacityToken()
return &tb
} | go | func newTokenBucket(capacity int64, tokenInterval time.Duration) *tokenBucket {
tb := tokenBucket{
capacity: capacity,
tokenInterval: tokenInterval,
refillDuration: tokenInterval * time.Duration(capacity)}
tb.earliestUnspentToken = tb.capacityToken()
return &tb
} | [
"func",
"newTokenBucket",
"(",
"capacity",
"int64",
",",
"tokenInterval",
"time",
".",
"Duration",
")",
"*",
"tokenBucket",
"{",
"tb",
":=",
"tokenBucket",
"{",
"capacity",
":",
"capacity",
",",
"tokenInterval",
":",
"tokenInterval",
",",
"refillDuration",
":",
... | // newTokenBucket returns a bucket containing capacity tokens, refilled at a
// rate of one token per tokenInterval. | [
"newTokenBucket",
"returns",
"a",
"bucket",
"containing",
"capacity",
"tokens",
"refilled",
"at",
"a",
"rate",
"of",
"one",
"token",
"per",
"tokenInterval",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/token_bucket.go#L18-L27 | test |
weaveworks/mesh | token_bucket.go | wait | func (tb *tokenBucket) wait() {
// If earliest unspent token is in the future, sleep until then
time.Sleep(time.Until(tb.earliestUnspentToken))
// Alternatively, enforce bucket capacity if necessary
capacityToken := tb.capacityToken()
if tb.earliestUnspentToken.Before(capacityToken) {
tb.earliestUnspentToken = ... | go | func (tb *tokenBucket) wait() {
// If earliest unspent token is in the future, sleep until then
time.Sleep(time.Until(tb.earliestUnspentToken))
// Alternatively, enforce bucket capacity if necessary
capacityToken := tb.capacityToken()
if tb.earliestUnspentToken.Before(capacityToken) {
tb.earliestUnspentToken = ... | [
"func",
"(",
"tb",
"*",
"tokenBucket",
")",
"wait",
"(",
")",
"{",
"time",
".",
"Sleep",
"(",
"time",
".",
"Until",
"(",
"tb",
".",
"earliestUnspentToken",
")",
")",
"\n",
"capacityToken",
":=",
"tb",
".",
"capacityToken",
"(",
")",
"\n",
"if",
"tb",... | // Blocks until there is a token available.
// Not safe for concurrent use by multiple goroutines. | [
"Blocks",
"until",
"there",
"is",
"a",
"token",
"available",
".",
"Not",
"safe",
"for",
"concurrent",
"use",
"by",
"multiple",
"goroutines",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/token_bucket.go#L31-L43 | test |
weaveworks/mesh | token_bucket.go | capacityToken | func (tb *tokenBucket) capacityToken() time.Time {
return time.Now().Add(-tb.refillDuration).Truncate(tb.tokenInterval)
} | go | func (tb *tokenBucket) capacityToken() time.Time {
return time.Now().Add(-tb.refillDuration).Truncate(tb.tokenInterval)
} | [
"func",
"(",
"tb",
"*",
"tokenBucket",
")",
"capacityToken",
"(",
")",
"time",
".",
"Time",
"{",
"return",
"time",
".",
"Now",
"(",
")",
".",
"Add",
"(",
"-",
"tb",
".",
"refillDuration",
")",
".",
"Truncate",
"(",
"tb",
".",
"tokenInterval",
")",
... | // Determine the historic token timestamp representing a full bucket | [
"Determine",
"the",
"historic",
"token",
"timestamp",
"representing",
"a",
"full",
"bucket"
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/token_bucket.go#L46-L48 | test |
weaveworks/mesh | _metcd/key_helpers.go | PrefixRangeEnd | func PrefixRangeEnd(prefix []byte) []byte {
// https://github.com/coreos/etcd/blob/17e32b6/clientv3/op.go#L187
end := make([]byte, len(prefix))
copy(end, prefix)
for i := len(end) - 1; i >= 0; i-- {
if end[i] < 0xff {
end[i] = end[i] + 1
end = end[:i+1]
return end
}
}
// next prefix does not exist (e... | go | func PrefixRangeEnd(prefix []byte) []byte {
// https://github.com/coreos/etcd/blob/17e32b6/clientv3/op.go#L187
end := make([]byte, len(prefix))
copy(end, prefix)
for i := len(end) - 1; i >= 0; i-- {
if end[i] < 0xff {
end[i] = end[i] + 1
end = end[:i+1]
return end
}
}
// next prefix does not exist (e... | [
"func",
"PrefixRangeEnd",
"(",
"prefix",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"end",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"len",
"(",
"prefix",
")",
")",
"\n",
"copy",
"(",
"end",
",",
"prefix",
")",
"\n",
"for",
"i",
":=",
"len",... | // PrefixRangeEnd allows Get, Delete, and Watch requests to operate on all keys
// with a matching prefix. Pass the prefix to this function, and use the result
// as the RangeEnd value. | [
"PrefixRangeEnd",
"allows",
"Get",
"Delete",
"and",
"Watch",
"requests",
"to",
"operate",
"on",
"all",
"keys",
"with",
"a",
"matching",
"prefix",
".",
"Pass",
"the",
"prefix",
"to",
"this",
"function",
"and",
"use",
"the",
"result",
"as",
"the",
"RangeEnd",
... | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/_metcd/key_helpers.go#L6-L20 | test |
weaveworks/mesh | local_peer.go | newLocalPeer | func newLocalPeer(name PeerName, nickName string, router *Router) *localPeer {
actionChan := make(chan localPeerAction, ChannelSize)
peer := &localPeer{
Peer: newPeer(name, nickName, randomPeerUID(), 0, randomPeerShortID()),
router: router,
actionChan: actionChan,
}
go peer.actorLoop(actionChan)
re... | go | func newLocalPeer(name PeerName, nickName string, router *Router) *localPeer {
actionChan := make(chan localPeerAction, ChannelSize)
peer := &localPeer{
Peer: newPeer(name, nickName, randomPeerUID(), 0, randomPeerShortID()),
router: router,
actionChan: actionChan,
}
go peer.actorLoop(actionChan)
re... | [
"func",
"newLocalPeer",
"(",
"name",
"PeerName",
",",
"nickName",
"string",
",",
"router",
"*",
"Router",
")",
"*",
"localPeer",
"{",
"actionChan",
":=",
"make",
"(",
"chan",
"localPeerAction",
",",
"ChannelSize",
")",
"\n",
"peer",
":=",
"&",
"localPeer",
... | // newLocalPeer returns a usable LocalPeer. | [
"newLocalPeer",
"returns",
"a",
"usable",
"LocalPeer",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/local_peer.go#L24-L33 | test |
weaveworks/mesh | local_peer.go | getConnections | func (peer *localPeer) getConnections() connectionSet {
connections := make(connectionSet)
peer.RLock()
defer peer.RUnlock()
for _, conn := range peer.connections {
connections[conn] = struct{}{}
}
return connections
} | go | func (peer *localPeer) getConnections() connectionSet {
connections := make(connectionSet)
peer.RLock()
defer peer.RUnlock()
for _, conn := range peer.connections {
connections[conn] = struct{}{}
}
return connections
} | [
"func",
"(",
"peer",
"*",
"localPeer",
")",
"getConnections",
"(",
")",
"connectionSet",
"{",
"connections",
":=",
"make",
"(",
"connectionSet",
")",
"\n",
"peer",
".",
"RLock",
"(",
")",
"\n",
"defer",
"peer",
".",
"RUnlock",
"(",
")",
"\n",
"for",
"_... | // Connections returns all the connections that the local peer is aware of. | [
"Connections",
"returns",
"all",
"the",
"connections",
"that",
"the",
"local",
"peer",
"is",
"aware",
"of",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/local_peer.go#L36-L44 | test |
weaveworks/mesh | local_peer.go | createConnection | func (peer *localPeer) createConnection(localAddr string, peerAddr string, acceptNewPeer bool, logger Logger) error {
if err := peer.checkConnectionLimit(); err != nil {
return err
}
localTCPAddr, err := net.ResolveTCPAddr("tcp", localAddr)
if err != nil {
return err
}
remoteTCPAddr, err := net.ResolveTCPAddr... | go | func (peer *localPeer) createConnection(localAddr string, peerAddr string, acceptNewPeer bool, logger Logger) error {
if err := peer.checkConnectionLimit(); err != nil {
return err
}
localTCPAddr, err := net.ResolveTCPAddr("tcp", localAddr)
if err != nil {
return err
}
remoteTCPAddr, err := net.ResolveTCPAddr... | [
"func",
"(",
"peer",
"*",
"localPeer",
")",
"createConnection",
"(",
"localAddr",
"string",
",",
"peerAddr",
"string",
",",
"acceptNewPeer",
"bool",
",",
"logger",
"Logger",
")",
"error",
"{",
"if",
"err",
":=",
"peer",
".",
"checkConnectionLimit",
"(",
")",... | // createConnection creates a new connection, originating from
// localAddr, to peerAddr. If acceptNewPeer is false, peerAddr must
// already be a member of the mesh. | [
"createConnection",
"creates",
"a",
"new",
"connection",
"originating",
"from",
"localAddr",
"to",
"peerAddr",
".",
"If",
"acceptNewPeer",
"is",
"false",
"peerAddr",
"must",
"already",
"be",
"a",
"member",
"of",
"the",
"mesh",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/local_peer.go#L81-L100 | test |
weaveworks/mesh | local_peer.go | doAddConnection | func (peer *localPeer) doAddConnection(conn ourConnection, isRestartedPeer bool) error {
resultChan := make(chan error)
peer.actionChan <- func() {
resultChan <- peer.handleAddConnection(conn, isRestartedPeer)
}
return <-resultChan
} | go | func (peer *localPeer) doAddConnection(conn ourConnection, isRestartedPeer bool) error {
resultChan := make(chan error)
peer.actionChan <- func() {
resultChan <- peer.handleAddConnection(conn, isRestartedPeer)
}
return <-resultChan
} | [
"func",
"(",
"peer",
"*",
"localPeer",
")",
"doAddConnection",
"(",
"conn",
"ourConnection",
",",
"isRestartedPeer",
"bool",
")",
"error",
"{",
"resultChan",
":=",
"make",
"(",
"chan",
"error",
")",
"\n",
"peer",
".",
"actionChan",
"<-",
"func",
"(",
")",
... | // ACTOR client API
// Synchronous. | [
"ACTOR",
"client",
"API",
"Synchronous",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/local_peer.go#L105-L111 | test |
weaveworks/mesh | connection.go | startLocalConnection | func startLocalConnection(connRemote *remoteConnection, tcpConn *net.TCPConn, router *Router, acceptNewPeer bool, logger Logger) {
if connRemote.local != router.Ourself.Peer {
panic("attempt to create local connection from a peer which is not ourself")
}
errorChan := make(chan error, 1)
finished := make(chan stru... | go | func startLocalConnection(connRemote *remoteConnection, tcpConn *net.TCPConn, router *Router, acceptNewPeer bool, logger Logger) {
if connRemote.local != router.Ourself.Peer {
panic("attempt to create local connection from a peer which is not ourself")
}
errorChan := make(chan error, 1)
finished := make(chan stru... | [
"func",
"startLocalConnection",
"(",
"connRemote",
"*",
"remoteConnection",
",",
"tcpConn",
"*",
"net",
".",
"TCPConn",
",",
"router",
"*",
"Router",
",",
"acceptNewPeer",
"bool",
",",
"logger",
"Logger",
")",
"{",
"if",
"connRemote",
".",
"local",
"!=",
"ro... | // If the connection is successful, it will end up in the local peer's
// connections map. | [
"If",
"the",
"connection",
"is",
"successful",
"it",
"will",
"end",
"up",
"in",
"the",
"local",
"peer",
"s",
"connections",
"map",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/connection.go#L82-L100 | test |
weaveworks/mesh | connection.go | SendProtocolMsg | func (conn *LocalConnection) SendProtocolMsg(m protocolMsg) error {
if err := conn.sendProtocolMsg(m); err != nil {
conn.shutdown(err)
return err
}
return nil
} | go | func (conn *LocalConnection) SendProtocolMsg(m protocolMsg) error {
if err := conn.sendProtocolMsg(m); err != nil {
conn.shutdown(err)
return err
}
return nil
} | [
"func",
"(",
"conn",
"*",
"LocalConnection",
")",
"SendProtocolMsg",
"(",
"m",
"protocolMsg",
")",
"error",
"{",
"if",
"err",
":=",
"conn",
".",
"sendProtocolMsg",
"(",
"m",
")",
";",
"err",
"!=",
"nil",
"{",
"conn",
".",
"shutdown",
"(",
"err",
")",
... | // SendProtocolMsg implements ProtocolSender. | [
"SendProtocolMsg",
"implements",
"ProtocolSender",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/connection.go#L126-L132 | test |
weaveworks/mesh | status.go | NewStatus | func NewStatus(router *Router) *Status {
return &Status{
Protocol: Protocol,
ProtocolMinVersion: int(router.ProtocolMinVersion),
ProtocolMaxVersion: ProtocolMaxVersion,
Encryption: router.usingPassword(),
PeerDiscovery: router.PeerDiscovery,
Name: router.Ourself.Name.St... | go | func NewStatus(router *Router) *Status {
return &Status{
Protocol: Protocol,
ProtocolMinVersion: int(router.ProtocolMinVersion),
ProtocolMaxVersion: ProtocolMaxVersion,
Encryption: router.usingPassword(),
PeerDiscovery: router.PeerDiscovery,
Name: router.Ourself.Name.St... | [
"func",
"NewStatus",
"(",
"router",
"*",
"Router",
")",
"*",
"Status",
"{",
"return",
"&",
"Status",
"{",
"Protocol",
":",
"Protocol",
",",
"ProtocolMinVersion",
":",
"int",
"(",
"router",
".",
"ProtocolMinVersion",
")",
",",
"ProtocolMaxVersion",
":",
"Prot... | // NewStatus returns a Status object, taken as a snapshot from the router. | [
"NewStatus",
"returns",
"a",
"Status",
"object",
"taken",
"as",
"a",
"snapshot",
"from",
"the",
"router",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/status.go#L30-L49 | test |
weaveworks/mesh | status.go | makePeerStatusSlice | func makePeerStatusSlice(peers *Peers) []PeerStatus {
var slice []PeerStatus
peers.forEach(func(peer *Peer) {
var connections []connectionStatus
if peer == peers.ourself.Peer {
for conn := range peers.ourself.getConnections() {
connections = append(connections, makeConnectionStatus(conn))
}
} else {
... | go | func makePeerStatusSlice(peers *Peers) []PeerStatus {
var slice []PeerStatus
peers.forEach(func(peer *Peer) {
var connections []connectionStatus
if peer == peers.ourself.Peer {
for conn := range peers.ourself.getConnections() {
connections = append(connections, makeConnectionStatus(conn))
}
} else {
... | [
"func",
"makePeerStatusSlice",
"(",
"peers",
"*",
"Peers",
")",
"[",
"]",
"PeerStatus",
"{",
"var",
"slice",
"[",
"]",
"PeerStatus",
"\n",
"peers",
".",
"forEach",
"(",
"func",
"(",
"peer",
"*",
"Peer",
")",
"{",
"var",
"connections",
"[",
"]",
"connec... | // makePeerStatusSlice takes a snapshot of the state of peers. | [
"makePeerStatusSlice",
"takes",
"a",
"snapshot",
"of",
"the",
"state",
"of",
"peers",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/status.go#L62-L90 | test |
weaveworks/mesh | status.go | makeUnicastRouteStatusSlice | func makeUnicastRouteStatusSlice(r *routes) []unicastRouteStatus {
r.RLock()
defer r.RUnlock()
var slice []unicastRouteStatus
for dest, via := range r.unicast {
slice = append(slice, unicastRouteStatus{dest.String(), via.String()})
}
return slice
} | go | func makeUnicastRouteStatusSlice(r *routes) []unicastRouteStatus {
r.RLock()
defer r.RUnlock()
var slice []unicastRouteStatus
for dest, via := range r.unicast {
slice = append(slice, unicastRouteStatus{dest.String(), via.String()})
}
return slice
} | [
"func",
"makeUnicastRouteStatusSlice",
"(",
"r",
"*",
"routes",
")",
"[",
"]",
"unicastRouteStatus",
"{",
"r",
".",
"RLock",
"(",
")",
"\n",
"defer",
"r",
".",
"RUnlock",
"(",
")",
"\n",
"var",
"slice",
"[",
"]",
"unicastRouteStatus",
"\n",
"for",
"dest"... | // makeUnicastRouteStatusSlice takes a snapshot of the unicast routes in routes. | [
"makeUnicastRouteStatusSlice",
"takes",
"a",
"snapshot",
"of",
"the",
"unicast",
"routes",
"in",
"routes",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/status.go#L116-L125 | test |
weaveworks/mesh | status.go | makeBroadcastRouteStatusSlice | func makeBroadcastRouteStatusSlice(r *routes) []broadcastRouteStatus {
r.RLock()
defer r.RUnlock()
var slice []broadcastRouteStatus
for source, via := range r.broadcast {
var hops []string
for _, hop := range via {
hops = append(hops, hop.String())
}
slice = append(slice, broadcastRouteStatus{source.Str... | go | func makeBroadcastRouteStatusSlice(r *routes) []broadcastRouteStatus {
r.RLock()
defer r.RUnlock()
var slice []broadcastRouteStatus
for source, via := range r.broadcast {
var hops []string
for _, hop := range via {
hops = append(hops, hop.String())
}
slice = append(slice, broadcastRouteStatus{source.Str... | [
"func",
"makeBroadcastRouteStatusSlice",
"(",
"r",
"*",
"routes",
")",
"[",
"]",
"broadcastRouteStatus",
"{",
"r",
".",
"RLock",
"(",
")",
"\n",
"defer",
"r",
".",
"RUnlock",
"(",
")",
"\n",
"var",
"slice",
"[",
"]",
"broadcastRouteStatus",
"\n",
"for",
... | // makeBroadcastRouteStatusSlice takes a snapshot of the broadcast routes in routes. | [
"makeBroadcastRouteStatusSlice",
"takes",
"a",
"snapshot",
"of",
"the",
"broadcast",
"routes",
"in",
"routes",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/status.go#L134-L147 | test |
weaveworks/mesh | status.go | makeLocalConnectionStatusSlice | func makeLocalConnectionStatusSlice(cm *connectionMaker) []LocalConnectionStatus {
resultChan := make(chan []LocalConnectionStatus)
cm.actionChan <- func() bool {
var slice []LocalConnectionStatus
for conn := range cm.connections {
state := "pending"
if conn.isEstablished() {
state = "established"
}
... | go | func makeLocalConnectionStatusSlice(cm *connectionMaker) []LocalConnectionStatus {
resultChan := make(chan []LocalConnectionStatus)
cm.actionChan <- func() bool {
var slice []LocalConnectionStatus
for conn := range cm.connections {
state := "pending"
if conn.isEstablished() {
state = "established"
}
... | [
"func",
"makeLocalConnectionStatusSlice",
"(",
"cm",
"*",
"connectionMaker",
")",
"[",
"]",
"LocalConnectionStatus",
"{",
"resultChan",
":=",
"make",
"(",
"chan",
"[",
"]",
"LocalConnectionStatus",
")",
"\n",
"cm",
".",
"actionChan",
"<-",
"func",
"(",
")",
"b... | // makeLocalConnectionStatusSlice takes a snapshot of the active local
// connections in the ConnectionMaker. | [
"makeLocalConnectionStatusSlice",
"takes",
"a",
"snapshot",
"of",
"the",
"active",
"local",
"connections",
"in",
"the",
"ConnectionMaker",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/status.go#L160-L217 | test |
weaveworks/mesh | status.go | makeTrustedSubnetsSlice | func makeTrustedSubnetsSlice(trustedSubnets []*net.IPNet) []string {
trustedSubnetStrs := []string{}
for _, trustedSubnet := range trustedSubnets {
trustedSubnetStrs = append(trustedSubnetStrs, trustedSubnet.String())
}
return trustedSubnetStrs
} | go | func makeTrustedSubnetsSlice(trustedSubnets []*net.IPNet) []string {
trustedSubnetStrs := []string{}
for _, trustedSubnet := range trustedSubnets {
trustedSubnetStrs = append(trustedSubnetStrs, trustedSubnet.String())
}
return trustedSubnetStrs
} | [
"func",
"makeTrustedSubnetsSlice",
"(",
"trustedSubnets",
"[",
"]",
"*",
"net",
".",
"IPNet",
")",
"[",
"]",
"string",
"{",
"trustedSubnetStrs",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"trustedSubnet",
":=",
"range",
"trustedSubnets",
"{... | // makeTrustedSubnetsSlice makes a human-readable copy of the trustedSubnets. | [
"makeTrustedSubnetsSlice",
"makes",
"a",
"human",
"-",
"readable",
"copy",
"of",
"the",
"trustedSubnets",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/status.go#L220-L226 | test |
weaveworks/mesh | _metcd/etcd_store.go | Range | func (s *etcdStore) Range(ctx context.Context, req *etcdserverpb.RangeRequest) (*etcdserverpb.RangeResponse, error) {
ireq := etcdserverpb.InternalRaftRequest{ID: <-s.idgen, Range: req}
msgc, errc, err := s.proposeInternalRaftRequest(ireq)
if err != nil {
return nil, err
}
select {
case <-ctx.Done():
s.cancel... | go | func (s *etcdStore) Range(ctx context.Context, req *etcdserverpb.RangeRequest) (*etcdserverpb.RangeResponse, error) {
ireq := etcdserverpb.InternalRaftRequest{ID: <-s.idgen, Range: req}
msgc, errc, err := s.proposeInternalRaftRequest(ireq)
if err != nil {
return nil, err
}
select {
case <-ctx.Done():
s.cancel... | [
"func",
"(",
"s",
"*",
"etcdStore",
")",
"Range",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"etcdserverpb",
".",
"RangeRequest",
")",
"(",
"*",
"etcdserverpb",
".",
"RangeResponse",
",",
"error",
")",
"{",
"ireq",
":=",
"etcdserverpb",
".",... | // Range implements gRPC KVServer.
// Range gets the keys in the range from the store. | [
"Range",
"implements",
"gRPC",
"KVServer",
".",
"Range",
"gets",
"the",
"keys",
"in",
"the",
"range",
"from",
"the",
"store",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/_metcd/etcd_store.go#L94-L111 | test |
weaveworks/mesh | _metcd/etcd_store.go | Put | func (s *etcdStore) Put(ctx context.Context, req *etcdserverpb.PutRequest) (*etcdserverpb.PutResponse, error) {
ireq := etcdserverpb.InternalRaftRequest{ID: <-s.idgen, Put: req}
msgc, errc, err := s.proposeInternalRaftRequest(ireq)
if err != nil {
return nil, err
}
select {
case <-ctx.Done():
s.cancelInternal... | go | func (s *etcdStore) Put(ctx context.Context, req *etcdserverpb.PutRequest) (*etcdserverpb.PutResponse, error) {
ireq := etcdserverpb.InternalRaftRequest{ID: <-s.idgen, Put: req}
msgc, errc, err := s.proposeInternalRaftRequest(ireq)
if err != nil {
return nil, err
}
select {
case <-ctx.Done():
s.cancelInternal... | [
"func",
"(",
"s",
"*",
"etcdStore",
")",
"Put",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"etcdserverpb",
".",
"PutRequest",
")",
"(",
"*",
"etcdserverpb",
".",
"PutResponse",
",",
"error",
")",
"{",
"ireq",
":=",
"etcdserverpb",
".",
"In... | // Put implements gRPC KVServer.
// Put puts the given key into the store.
// A put request increases the revision of the store,
// and generates one event in the event history. | [
"Put",
"implements",
"gRPC",
"KVServer",
".",
"Put",
"puts",
"the",
"given",
"key",
"into",
"the",
"store",
".",
"A",
"put",
"request",
"increases",
"the",
"revision",
"of",
"the",
"store",
"and",
"generates",
"one",
"event",
"in",
"the",
"event",
"history... | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/_metcd/etcd_store.go#L117-L134 | test |
weaveworks/mesh | _metcd/etcd_store.go | DeleteRange | func (s *etcdStore) DeleteRange(ctx context.Context, req *etcdserverpb.DeleteRangeRequest) (*etcdserverpb.DeleteRangeResponse, error) {
ireq := etcdserverpb.InternalRaftRequest{ID: <-s.idgen, DeleteRange: req}
msgc, errc, err := s.proposeInternalRaftRequest(ireq)
if err != nil {
return nil, err
}
select {
case ... | go | func (s *etcdStore) DeleteRange(ctx context.Context, req *etcdserverpb.DeleteRangeRequest) (*etcdserverpb.DeleteRangeResponse, error) {
ireq := etcdserverpb.InternalRaftRequest{ID: <-s.idgen, DeleteRange: req}
msgc, errc, err := s.proposeInternalRaftRequest(ireq)
if err != nil {
return nil, err
}
select {
case ... | [
"func",
"(",
"s",
"*",
"etcdStore",
")",
"DeleteRange",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"etcdserverpb",
".",
"DeleteRangeRequest",
")",
"(",
"*",
"etcdserverpb",
".",
"DeleteRangeResponse",
",",
"error",
")",
"{",
"ireq",
":=",
"etc... | // Delete implements gRPC KVServer.
// Delete deletes the given range from the store.
// A delete request increase the revision of the store,
// and generates one event in the event history. | [
"Delete",
"implements",
"gRPC",
"KVServer",
".",
"Delete",
"deletes",
"the",
"given",
"range",
"from",
"the",
"store",
".",
"A",
"delete",
"request",
"increase",
"the",
"revision",
"of",
"the",
"store",
"and",
"generates",
"one",
"event",
"in",
"the",
"event... | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/_metcd/etcd_store.go#L140-L157 | test |
weaveworks/mesh | _metcd/etcd_store.go | Txn | func (s *etcdStore) Txn(ctx context.Context, req *etcdserverpb.TxnRequest) (*etcdserverpb.TxnResponse, error) {
ireq := etcdserverpb.InternalRaftRequest{ID: <-s.idgen, Txn: req}
msgc, errc, err := s.proposeInternalRaftRequest(ireq)
if err != nil {
return nil, err
}
select {
case <-ctx.Done():
s.cancelInternal... | go | func (s *etcdStore) Txn(ctx context.Context, req *etcdserverpb.TxnRequest) (*etcdserverpb.TxnResponse, error) {
ireq := etcdserverpb.InternalRaftRequest{ID: <-s.idgen, Txn: req}
msgc, errc, err := s.proposeInternalRaftRequest(ireq)
if err != nil {
return nil, err
}
select {
case <-ctx.Done():
s.cancelInternal... | [
"func",
"(",
"s",
"*",
"etcdStore",
")",
"Txn",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"etcdserverpb",
".",
"TxnRequest",
")",
"(",
"*",
"etcdserverpb",
".",
"TxnResponse",
",",
"error",
")",
"{",
"ireq",
":=",
"etcdserverpb",
".",
"In... | // Txn implements gRPC KVServer.
// Txn processes all the requests in one transaction.
// A txn request increases the revision of the store,
// and generates events with the same revision in the event history.
// It is not allowed to modify the same key several times within one txn. | [
"Txn",
"implements",
"gRPC",
"KVServer",
".",
"Txn",
"processes",
"all",
"the",
"requests",
"in",
"one",
"transaction",
".",
"A",
"txn",
"request",
"increases",
"the",
"revision",
"of",
"the",
"store",
"and",
"generates",
"events",
"with",
"the",
"same",
"re... | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/_metcd/etcd_store.go#L164-L181 | test |
weaveworks/mesh | _metcd/etcd_store.go | Compact | func (s *etcdStore) Compact(ctx context.Context, req *etcdserverpb.CompactionRequest) (*etcdserverpb.CompactionResponse, error) {
// We don't have snapshotting yet, so compact just puts us in a bad state.
// TODO(pb): fix this when we implement snapshotting.
return nil, errors.New("not implemented")
} | go | func (s *etcdStore) Compact(ctx context.Context, req *etcdserverpb.CompactionRequest) (*etcdserverpb.CompactionResponse, error) {
// We don't have snapshotting yet, so compact just puts us in a bad state.
// TODO(pb): fix this when we implement snapshotting.
return nil, errors.New("not implemented")
} | [
"func",
"(",
"s",
"*",
"etcdStore",
")",
"Compact",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"etcdserverpb",
".",
"CompactionRequest",
")",
"(",
"*",
"etcdserverpb",
".",
"CompactionResponse",
",",
"error",
")",
"{",
"return",
"nil",
",",
... | // Compact implements gRPC KVServer.
// Compact compacts the event history in s. User should compact the
// event history periodically, or it will grow infinitely. | [
"Compact",
"implements",
"gRPC",
"KVServer",
".",
"Compact",
"compacts",
"the",
"event",
"history",
"in",
"s",
".",
"User",
"should",
"compact",
"the",
"event",
"history",
"periodically",
"or",
"it",
"will",
"grow",
"infinitely",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/_metcd/etcd_store.go#L186-L190 | test |
weaveworks/mesh | _metcd/etcd_store.go | proposeInternalRaftRequest | func (s *etcdStore) proposeInternalRaftRequest(req etcdserverpb.InternalRaftRequest) (<-chan proto.Message, <-chan error, error) {
data, err := req.Marshal()
if err != nil {
return nil, nil, err
}
if len(data) > maxRequestBytes {
return nil, nil, errTooBig
}
msgc, errc, err := s.registerPending(req.ID)
if er... | go | func (s *etcdStore) proposeInternalRaftRequest(req etcdserverpb.InternalRaftRequest) (<-chan proto.Message, <-chan error, error) {
data, err := req.Marshal()
if err != nil {
return nil, nil, err
}
if len(data) > maxRequestBytes {
return nil, nil, errTooBig
}
msgc, errc, err := s.registerPending(req.ID)
if er... | [
"func",
"(",
"s",
"*",
"etcdStore",
")",
"proposeInternalRaftRequest",
"(",
"req",
"etcdserverpb",
".",
"InternalRaftRequest",
")",
"(",
"<-",
"chan",
"proto",
".",
"Message",
",",
"<-",
"chan",
"error",
",",
"error",
")",
"{",
"data",
",",
"err",
":=",
... | // From public API method to proposalc. | [
"From",
"public",
"API",
"method",
"to",
"proposalc",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/_metcd/etcd_store.go#L333-L347 | test |
weaveworks/mesh | _metcd/etcd_store.go | applyCompare | func applyCompare(kv mvcc.KV, c *etcdserverpb.Compare) (int64, bool) {
ckvs, rev, err := kv.Range(c.Key, nil, 1, 0)
if err != nil {
if err == mvcc.ErrTxnIDMismatch {
panic("unexpected txn ID mismatch error")
}
return rev, false
}
var ckv mvccpb.KeyValue
if len(ckvs) != 0 {
ckv = ckvs[0]
} else {
// U... | go | func applyCompare(kv mvcc.KV, c *etcdserverpb.Compare) (int64, bool) {
ckvs, rev, err := kv.Range(c.Key, nil, 1, 0)
if err != nil {
if err == mvcc.ErrTxnIDMismatch {
panic("unexpected txn ID mismatch error")
}
return rev, false
}
var ckv mvccpb.KeyValue
if len(ckvs) != 0 {
ckv = ckvs[0]
} else {
// U... | [
"func",
"applyCompare",
"(",
"kv",
"mvcc",
".",
"KV",
",",
"c",
"*",
"etcdserverpb",
".",
"Compare",
")",
"(",
"int64",
",",
"bool",
")",
"{",
"ckvs",
",",
"rev",
",",
"err",
":=",
"kv",
".",
"Range",
"(",
"c",
".",
"Key",
",",
"nil",
",",
"1",... | // applyCompare applies the compare request.
// It returns the revision at which the comparison happens. If the comparison
// succeeds, the it returns true. Otherwise it returns false. | [
"applyCompare",
"applies",
"the",
"compare",
"request",
".",
"It",
"returns",
"the",
"revision",
"at",
"which",
"the",
"comparison",
"happens",
".",
"If",
"the",
"comparison",
"succeeds",
"the",
"it",
"returns",
"true",
".",
"Otherwise",
"it",
"returns",
"fals... | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/_metcd/etcd_store.go#L712-L775 | test |
weaveworks/mesh | peers.go | Descriptions | func (peers *Peers) Descriptions() []PeerDescription {
peers.RLock()
defer peers.RUnlock()
descriptions := make([]PeerDescription, 0, len(peers.byName))
for _, peer := range peers.byName {
descriptions = append(descriptions, PeerDescription{
Name: peer.Name,
NickName: peer.peerSummary.NickNa... | go | func (peers *Peers) Descriptions() []PeerDescription {
peers.RLock()
defer peers.RUnlock()
descriptions := make([]PeerDescription, 0, len(peers.byName))
for _, peer := range peers.byName {
descriptions = append(descriptions, PeerDescription{
Name: peer.Name,
NickName: peer.peerSummary.NickNa... | [
"func",
"(",
"peers",
"*",
"Peers",
")",
"Descriptions",
"(",
")",
"[",
"]",
"PeerDescription",
"{",
"peers",
".",
"RLock",
"(",
")",
"\n",
"defer",
"peers",
".",
"RUnlock",
"(",
")",
"\n",
"descriptions",
":=",
"make",
"(",
"[",
"]",
"PeerDescription"... | // Descriptions returns descriptions for all known peers. | [
"Descriptions",
"returns",
"descriptions",
"for",
"all",
"known",
"peers",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/peers.go#L69-L83 | test |
weaveworks/mesh | peers.go | OnGC | func (peers *Peers) OnGC(callback func(*Peer)) {
peers.Lock()
defer peers.Unlock()
// Although the array underlying peers.onGC might be accessed
// without holding the lock in unlockAndNotify, we don't
// support removing callbacks, so a simple append here is
// safe.
peers.onGC = append(peers.onGC, callback)
} | go | func (peers *Peers) OnGC(callback func(*Peer)) {
peers.Lock()
defer peers.Unlock()
// Although the array underlying peers.onGC might be accessed
// without holding the lock in unlockAndNotify, we don't
// support removing callbacks, so a simple append here is
// safe.
peers.onGC = append(peers.onGC, callback)
} | [
"func",
"(",
"peers",
"*",
"Peers",
")",
"OnGC",
"(",
"callback",
"func",
"(",
"*",
"Peer",
")",
")",
"{",
"peers",
".",
"Lock",
"(",
")",
"\n",
"defer",
"peers",
".",
"Unlock",
"(",
")",
"\n",
"peers",
".",
"onGC",
"=",
"append",
"(",
"peers",
... | // OnGC adds a new function to be set of functions that will be executed on
// all subsequent GC runs, receiving the GC'd peer. | [
"OnGC",
"adds",
"a",
"new",
"function",
"to",
"be",
"set",
"of",
"functions",
"that",
"will",
"be",
"executed",
"on",
"all",
"subsequent",
"GC",
"runs",
"receiving",
"the",
"GC",
"d",
"peer",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/peers.go#L87-L96 | test |
weaveworks/mesh | peers.go | OnInvalidateShortIDs | func (peers *Peers) OnInvalidateShortIDs(callback func()) {
peers.Lock()
defer peers.Unlock()
// Safe, as in OnGC
peers.onInvalidateShortIDs = append(peers.onInvalidateShortIDs, callback)
} | go | func (peers *Peers) OnInvalidateShortIDs(callback func()) {
peers.Lock()
defer peers.Unlock()
// Safe, as in OnGC
peers.onInvalidateShortIDs = append(peers.onInvalidateShortIDs, callback)
} | [
"func",
"(",
"peers",
"*",
"Peers",
")",
"OnInvalidateShortIDs",
"(",
"callback",
"func",
"(",
")",
")",
"{",
"peers",
".",
"Lock",
"(",
")",
"\n",
"defer",
"peers",
".",
"Unlock",
"(",
")",
"\n",
"peers",
".",
"onInvalidateShortIDs",
"=",
"append",
"(... | // OnInvalidateShortIDs adds a new function to a set of functions that will be
// executed on all subsequent GC runs, when the mapping from short IDs to
// peers has changed. | [
"OnInvalidateShortIDs",
"adds",
"a",
"new",
"function",
"to",
"a",
"set",
"of",
"functions",
"that",
"will",
"be",
"executed",
"on",
"all",
"subsequent",
"GC",
"runs",
"when",
"the",
"mapping",
"from",
"short",
"IDs",
"to",
"peers",
"has",
"changed",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/peers.go#L101-L107 | test |
weaveworks/mesh | peers.go | chooseShortID | func (peers *Peers) chooseShortID() (PeerShortID, bool) {
rng := rand.New(rand.NewSource(int64(randUint64())))
// First, just try picking some short IDs at random, and
// seeing if they are available:
for i := 0; i < 10; i++ {
shortID := PeerShortID(rng.Intn(1 << peerShortIDBits))
if peers.byShortID[shortID].p... | go | func (peers *Peers) chooseShortID() (PeerShortID, bool) {
rng := rand.New(rand.NewSource(int64(randUint64())))
// First, just try picking some short IDs at random, and
// seeing if they are available:
for i := 0; i < 10; i++ {
shortID := PeerShortID(rng.Intn(1 << peerShortIDBits))
if peers.byShortID[shortID].p... | [
"func",
"(",
"peers",
"*",
"Peers",
")",
"chooseShortID",
"(",
")",
"(",
"PeerShortID",
",",
"bool",
")",
"{",
"rng",
":=",
"rand",
".",
"New",
"(",
"rand",
".",
"NewSource",
"(",
"int64",
"(",
"randUint64",
"(",
")",
")",
")",
")",
"\n",
"for",
... | // Choose an available short ID at random. | [
"Choose",
"an",
"available",
"short",
"ID",
"at",
"random",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/peers.go#L239-L278 | test |
weaveworks/mesh | peers.go | fetchWithDefault | func (peers *Peers) fetchWithDefault(peer *Peer) *Peer {
peers.Lock()
var pending peersPendingNotifications
defer peers.unlockAndNotify(&pending)
if existingPeer, found := peers.byName[peer.Name]; found {
existingPeer.localRefCount++
return existingPeer
}
peers.byName[peer.Name] = peer
peers.addByShortID(p... | go | func (peers *Peers) fetchWithDefault(peer *Peer) *Peer {
peers.Lock()
var pending peersPendingNotifications
defer peers.unlockAndNotify(&pending)
if existingPeer, found := peers.byName[peer.Name]; found {
existingPeer.localRefCount++
return existingPeer
}
peers.byName[peer.Name] = peer
peers.addByShortID(p... | [
"func",
"(",
"peers",
"*",
"Peers",
")",
"fetchWithDefault",
"(",
"peer",
"*",
"Peer",
")",
"*",
"Peer",
"{",
"peers",
".",
"Lock",
"(",
")",
"\n",
"var",
"pending",
"peersPendingNotifications",
"\n",
"defer",
"peers",
".",
"unlockAndNotify",
"(",
"&",
"... | // fetchWithDefault will use reference fields of the passed peer object to
// look up and return an existing, matching peer. If no matching peer is
// found, the passed peer is saved and returned. | [
"fetchWithDefault",
"will",
"use",
"reference",
"fields",
"of",
"the",
"passed",
"peer",
"object",
"to",
"look",
"up",
"and",
"return",
"an",
"existing",
"matching",
"peer",
".",
"If",
"no",
"matching",
"peer",
"is",
"found",
"the",
"passed",
"peer",
"is",
... | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/peers.go#L283-L297 | test |
weaveworks/mesh | peers.go | Fetch | func (peers *Peers) Fetch(name PeerName) *Peer {
peers.RLock()
defer peers.RUnlock()
return peers.byName[name]
} | go | func (peers *Peers) Fetch(name PeerName) *Peer {
peers.RLock()
defer peers.RUnlock()
return peers.byName[name]
} | [
"func",
"(",
"peers",
"*",
"Peers",
")",
"Fetch",
"(",
"name",
"PeerName",
")",
"*",
"Peer",
"{",
"peers",
".",
"RLock",
"(",
")",
"\n",
"defer",
"peers",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"peers",
".",
"byName",
"[",
"name",
"]",
"\n",
"... | // Fetch returns a peer matching the passed name, without incrementing its
// refcount. If no matching peer is found, Fetch returns nil. | [
"Fetch",
"returns",
"a",
"peer",
"matching",
"the",
"passed",
"name",
"without",
"incrementing",
"its",
"refcount",
".",
"If",
"no",
"matching",
"peer",
"is",
"found",
"Fetch",
"returns",
"nil",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/peers.go#L301-L305 | test |
weaveworks/mesh | peers.go | fetchAndAddRef | func (peers *Peers) fetchAndAddRef(name PeerName) *Peer {
peers.Lock()
defer peers.Unlock()
peer := peers.byName[name]
if peer != nil {
peer.localRefCount++
}
return peer
} | go | func (peers *Peers) fetchAndAddRef(name PeerName) *Peer {
peers.Lock()
defer peers.Unlock()
peer := peers.byName[name]
if peer != nil {
peer.localRefCount++
}
return peer
} | [
"func",
"(",
"peers",
"*",
"Peers",
")",
"fetchAndAddRef",
"(",
"name",
"PeerName",
")",
"*",
"Peer",
"{",
"peers",
".",
"Lock",
"(",
")",
"\n",
"defer",
"peers",
".",
"Unlock",
"(",
")",
"\n",
"peer",
":=",
"peers",
".",
"byName",
"[",
"name",
"]"... | // Like fetch, but increments local refcount. | [
"Like",
"fetch",
"but",
"increments",
"local",
"refcount",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/peers.go#L308-L316 | test |
weaveworks/mesh | peers.go | FetchByShortID | func (peers *Peers) FetchByShortID(shortID PeerShortID) *Peer {
peers.RLock()
defer peers.RUnlock()
return peers.byShortID[shortID].peer
} | go | func (peers *Peers) FetchByShortID(shortID PeerShortID) *Peer {
peers.RLock()
defer peers.RUnlock()
return peers.byShortID[shortID].peer
} | [
"func",
"(",
"peers",
"*",
"Peers",
")",
"FetchByShortID",
"(",
"shortID",
"PeerShortID",
")",
"*",
"Peer",
"{",
"peers",
".",
"RLock",
"(",
")",
"\n",
"defer",
"peers",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"peers",
".",
"byShortID",
"[",
"shortID... | // FetchByShortID returns a peer matching the passed short ID.
// If no matching peer is found, FetchByShortID returns nil. | [
"FetchByShortID",
"returns",
"a",
"peer",
"matching",
"the",
"passed",
"short",
"ID",
".",
"If",
"no",
"matching",
"peer",
"is",
"found",
"FetchByShortID",
"returns",
"nil",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/peers.go#L320-L324 | test |
weaveworks/mesh | peers.go | GarbageCollect | func (peers *Peers) GarbageCollect() {
peers.Lock()
var pending peersPendingNotifications
defer peers.unlockAndNotify(&pending)
peers.garbageCollect(&pending)
} | go | func (peers *Peers) GarbageCollect() {
peers.Lock()
var pending peersPendingNotifications
defer peers.unlockAndNotify(&pending)
peers.garbageCollect(&pending)
} | [
"func",
"(",
"peers",
"*",
"Peers",
")",
"GarbageCollect",
"(",
")",
"{",
"peers",
".",
"Lock",
"(",
")",
"\n",
"var",
"pending",
"peersPendingNotifications",
"\n",
"defer",
"peers",
".",
"unlockAndNotify",
"(",
"&",
"pending",
")",
"\n",
"peers",
".",
"... | // GarbageCollect takes a lock, triggers a GC, and invokes the accumulated GC
// callbacks. | [
"GarbageCollect",
"takes",
"a",
"lock",
"triggers",
"a",
"GC",
"and",
"invokes",
"the",
"accumulated",
"GC",
"callbacks",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/peers.go#L409-L415 | test |
weaveworks/mesh | routes.go | newRoutes | func newRoutes(ourself *localPeer, peers *Peers) *routes {
recalculate := make(chan *struct{}, 1)
wait := make(chan chan struct{})
action := make(chan func())
r := &routes{
ourself: ourself,
peers: peers,
unicast: unicastRoutes{ourself.Name: UnknownPeerName},
unicastAll: unicastRoutes{our... | go | func newRoutes(ourself *localPeer, peers *Peers) *routes {
recalculate := make(chan *struct{}, 1)
wait := make(chan chan struct{})
action := make(chan func())
r := &routes{
ourself: ourself,
peers: peers,
unicast: unicastRoutes{ourself.Name: UnknownPeerName},
unicastAll: unicastRoutes{our... | [
"func",
"newRoutes",
"(",
"ourself",
"*",
"localPeer",
",",
"peers",
"*",
"Peers",
")",
"*",
"routes",
"{",
"recalculate",
":=",
"make",
"(",
"chan",
"*",
"struct",
"{",
"}",
",",
"1",
")",
"\n",
"wait",
":=",
"make",
"(",
"chan",
"chan",
"struct",
... | // newRoutes returns a usable Routes based on the LocalPeer and existing Peers. | [
"newRoutes",
"returns",
"a",
"usable",
"Routes",
"based",
"on",
"the",
"LocalPeer",
"and",
"existing",
"Peers",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/routes.go#L29-L46 | test |
weaveworks/mesh | routes.go | OnChange | func (r *routes) OnChange(callback func()) {
r.Lock()
defer r.Unlock()
r.onChange = append(r.onChange, callback)
} | go | func (r *routes) OnChange(callback func()) {
r.Lock()
defer r.Unlock()
r.onChange = append(r.onChange, callback)
} | [
"func",
"(",
"r",
"*",
"routes",
")",
"OnChange",
"(",
"callback",
"func",
"(",
")",
")",
"{",
"r",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"Unlock",
"(",
")",
"\n",
"r",
".",
"onChange",
"=",
"append",
"(",
"r",
".",
"onChange",
",",
... | // OnChange appends callback to the functions that will be called whenever the
// routes are recalculated. | [
"OnChange",
"appends",
"callback",
"to",
"the",
"functions",
"that",
"will",
"be",
"called",
"whenever",
"the",
"routes",
"are",
"recalculated",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/routes.go#L50-L54 | test |
weaveworks/mesh | routes.go | Unicast | func (r *routes) Unicast(name PeerName) (PeerName, bool) {
r.RLock()
defer r.RUnlock()
hop, found := r.unicast[name]
return hop, found
} | go | func (r *routes) Unicast(name PeerName) (PeerName, bool) {
r.RLock()
defer r.RUnlock()
hop, found := r.unicast[name]
return hop, found
} | [
"func",
"(",
"r",
"*",
"routes",
")",
"Unicast",
"(",
"name",
"PeerName",
")",
"(",
"PeerName",
",",
"bool",
")",
"{",
"r",
".",
"RLock",
"(",
")",
"\n",
"defer",
"r",
".",
"RUnlock",
"(",
")",
"\n",
"hop",
",",
"found",
":=",
"r",
".",
"unicas... | // Unicast returns the next hop on the unicast route to the named peer,
// based on established and symmetric connections. | [
"Unicast",
"returns",
"the",
"next",
"hop",
"on",
"the",
"unicast",
"route",
"to",
"the",
"named",
"peer",
"based",
"on",
"established",
"and",
"symmetric",
"connections",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/routes.go#L63-L68 | test |
weaveworks/mesh | routes.go | UnicastAll | func (r *routes) UnicastAll(name PeerName) (PeerName, bool) {
r.RLock()
defer r.RUnlock()
hop, found := r.unicastAll[name]
return hop, found
} | go | func (r *routes) UnicastAll(name PeerName) (PeerName, bool) {
r.RLock()
defer r.RUnlock()
hop, found := r.unicastAll[name]
return hop, found
} | [
"func",
"(",
"r",
"*",
"routes",
")",
"UnicastAll",
"(",
"name",
"PeerName",
")",
"(",
"PeerName",
",",
"bool",
")",
"{",
"r",
".",
"RLock",
"(",
")",
"\n",
"defer",
"r",
".",
"RUnlock",
"(",
")",
"\n",
"hop",
",",
"found",
":=",
"r",
".",
"uni... | // UnicastAll returns the next hop on the unicast route to the named peer,
// based on all connections. | [
"UnicastAll",
"returns",
"the",
"next",
"hop",
"on",
"the",
"unicast",
"route",
"to",
"the",
"named",
"peer",
"based",
"on",
"all",
"connections",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/routes.go#L72-L77 | test |
weaveworks/mesh | routes.go | Broadcast | func (r *routes) Broadcast(name PeerName) []PeerName {
return r.lookupOrCalculate(name, &r.broadcast, true)
} | go | func (r *routes) Broadcast(name PeerName) []PeerName {
return r.lookupOrCalculate(name, &r.broadcast, true)
} | [
"func",
"(",
"r",
"*",
"routes",
")",
"Broadcast",
"(",
"name",
"PeerName",
")",
"[",
"]",
"PeerName",
"{",
"return",
"r",
".",
"lookupOrCalculate",
"(",
"name",
",",
"&",
"r",
".",
"broadcast",
",",
"true",
")",
"\n",
"}"
] | // Broadcast returns the set of peer names that should be notified
// when we receive a broadcast message originating from the named peer
// based on established and symmetric connections. | [
"Broadcast",
"returns",
"the",
"set",
"of",
"peer",
"names",
"that",
"should",
"be",
"notified",
"when",
"we",
"receive",
"a",
"broadcast",
"message",
"originating",
"from",
"the",
"named",
"peer",
"based",
"on",
"established",
"and",
"symmetric",
"connections",... | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/routes.go#L82-L84 | test |
weaveworks/mesh | routes.go | BroadcastAll | func (r *routes) BroadcastAll(name PeerName) []PeerName {
return r.lookupOrCalculate(name, &r.broadcastAll, false)
} | go | func (r *routes) BroadcastAll(name PeerName) []PeerName {
return r.lookupOrCalculate(name, &r.broadcastAll, false)
} | [
"func",
"(",
"r",
"*",
"routes",
")",
"BroadcastAll",
"(",
"name",
"PeerName",
")",
"[",
"]",
"PeerName",
"{",
"return",
"r",
".",
"lookupOrCalculate",
"(",
"name",
",",
"&",
"r",
".",
"broadcastAll",
",",
"false",
")",
"\n",
"}"
] | // BroadcastAll returns the set of peer names that should be notified
// when we receive a broadcast message originating from the named peer
// based on all connections. | [
"BroadcastAll",
"returns",
"the",
"set",
"of",
"peer",
"names",
"that",
"should",
"be",
"notified",
"when",
"we",
"receive",
"a",
"broadcast",
"message",
"originating",
"from",
"the",
"named",
"peer",
"based",
"on",
"all",
"connections",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/routes.go#L89-L91 | test |
weaveworks/mesh | meshconn/peer.go | NewPeer | func NewPeer(name mesh.PeerName, uid mesh.PeerUID, logger mesh.Logger) *Peer {
p := &Peer{
name: name,
uid: uid,
gossip: nil, // initially no gossip
recv: make(chan pkt),
actions: make(chan func()),
quit: make(chan struct{}),
logger: logger,
}
go p.loop()
return p
} | go | func NewPeer(name mesh.PeerName, uid mesh.PeerUID, logger mesh.Logger) *Peer {
p := &Peer{
name: name,
uid: uid,
gossip: nil, // initially no gossip
recv: make(chan pkt),
actions: make(chan func()),
quit: make(chan struct{}),
logger: logger,
}
go p.loop()
return p
} | [
"func",
"NewPeer",
"(",
"name",
"mesh",
".",
"PeerName",
",",
"uid",
"mesh",
".",
"PeerUID",
",",
"logger",
"mesh",
".",
"Logger",
")",
"*",
"Peer",
"{",
"p",
":=",
"&",
"Peer",
"{",
"name",
":",
"name",
",",
"uid",
":",
"uid",
",",
"gossip",
":"... | // NewPeer returns a Peer, which can be used as a net.PacketConn.
// Clients must Register a mesh.Gossip before calling ReadFrom or WriteTo.
// Clients should aggressively consume from ReadFrom. | [
"NewPeer",
"returns",
"a",
"Peer",
"which",
"can",
"be",
"used",
"as",
"a",
"net",
".",
"PacketConn",
".",
"Clients",
"must",
"Register",
"a",
"mesh",
".",
"Gossip",
"before",
"calling",
"ReadFrom",
"or",
"WriteTo",
".",
"Clients",
"should",
"aggressively",
... | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/meshconn/peer.go#L46-L58 | test |
weaveworks/mesh | meshconn/peer.go | Register | func (p *Peer) Register(gossip mesh.Gossip) {
p.actions <- func() { p.gossip = gossip }
} | go | func (p *Peer) Register(gossip mesh.Gossip) {
p.actions <- func() { p.gossip = gossip }
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"Register",
"(",
"gossip",
"mesh",
".",
"Gossip",
")",
"{",
"p",
".",
"actions",
"<-",
"func",
"(",
")",
"{",
"p",
".",
"gossip",
"=",
"gossip",
"}",
"\n",
"}"
] | // Register injects the mesh.Gossip and enables full-duplex communication.
// Clients should consume from ReadFrom without blocking. | [
"Register",
"injects",
"the",
"mesh",
".",
"Gossip",
"and",
"enables",
"full",
"-",
"duplex",
"communication",
".",
"Clients",
"should",
"consume",
"from",
"ReadFrom",
"without",
"blocking",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/meshconn/peer.go#L73-L75 | test |
weaveworks/mesh | meshconn/peer.go | ReadFrom | func (p *Peer) ReadFrom(b []byte) (n int, remote net.Addr, err error) {
c := make(chan struct{})
p.actions <- func() {
go func() { // so as not to block loop
defer close(c)
select {
case pkt := <-p.recv:
n = copy(b, pkt.Buf)
remote = MeshAddr{PeerName: pkt.SrcName, PeerUID: pkt.SrcUID}
if n < l... | go | func (p *Peer) ReadFrom(b []byte) (n int, remote net.Addr, err error) {
c := make(chan struct{})
p.actions <- func() {
go func() { // so as not to block loop
defer close(c)
select {
case pkt := <-p.recv:
n = copy(b, pkt.Buf)
remote = MeshAddr{PeerName: pkt.SrcName, PeerUID: pkt.SrcUID}
if n < l... | [
"func",
"(",
"p",
"*",
"Peer",
")",
"ReadFrom",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"remote",
"net",
".",
"Addr",
",",
"err",
"error",
")",
"{",
"c",
":=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"p",
".",
"ac... | // ReadFrom implements net.PacketConn.
// Clients should consume from ReadFrom without blocking. | [
"ReadFrom",
"implements",
"net",
".",
"PacketConn",
".",
"Clients",
"should",
"consume",
"from",
"ReadFrom",
"without",
"blocking",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/meshconn/peer.go#L79-L98 | test |
weaveworks/mesh | meshconn/peer.go | WriteTo | func (p *Peer) WriteTo(b []byte, dst net.Addr) (n int, err error) {
c := make(chan struct{})
p.actions <- func() {
defer close(c)
if p.gossip == nil {
err = ErrGossipNotRegistered
return
}
meshAddr, ok := dst.(MeshAddr)
if !ok {
err = ErrNotMeshAddr
return
}
pkt := pkt{SrcName: p.name, SrcUI... | go | func (p *Peer) WriteTo(b []byte, dst net.Addr) (n int, err error) {
c := make(chan struct{})
p.actions <- func() {
defer close(c)
if p.gossip == nil {
err = ErrGossipNotRegistered
return
}
meshAddr, ok := dst.(MeshAddr)
if !ok {
err = ErrNotMeshAddr
return
}
pkt := pkt{SrcName: p.name, SrcUI... | [
"func",
"(",
"p",
"*",
"Peer",
")",
"WriteTo",
"(",
"b",
"[",
"]",
"byte",
",",
"dst",
"net",
".",
"Addr",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"c",
":=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"p",
".",
"action... | // WriteTo implements net.PacketConn. | [
"WriteTo",
"implements",
"net",
".",
"PacketConn",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/meshconn/peer.go#L101-L126 | test |
weaveworks/mesh | meshconn/peer.go | LocalAddr | func (p *Peer) LocalAddr() net.Addr {
return MeshAddr{PeerName: p.name, PeerUID: p.uid}
} | go | func (p *Peer) LocalAddr() net.Addr {
return MeshAddr{PeerName: p.name, PeerUID: p.uid}
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"LocalAddr",
"(",
")",
"net",
".",
"Addr",
"{",
"return",
"MeshAddr",
"{",
"PeerName",
":",
"p",
".",
"name",
",",
"PeerUID",
":",
"p",
".",
"uid",
"}",
"\n",
"}"
] | // LocalAddr implements net.PacketConn. | [
"LocalAddr",
"implements",
"net",
".",
"PacketConn",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/meshconn/peer.go#L135-L137 | test |
weaveworks/mesh | meshconn/peer.go | OnGossip | func (p *Peer) OnGossip(buf []byte) (delta mesh.GossipData, err error) {
return pktSlice{makePkt(buf)}, nil
} | go | func (p *Peer) OnGossip(buf []byte) (delta mesh.GossipData, err error) {
return pktSlice{makePkt(buf)}, nil
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"OnGossip",
"(",
"buf",
"[",
"]",
"byte",
")",
"(",
"delta",
"mesh",
".",
"GossipData",
",",
"err",
"error",
")",
"{",
"return",
"pktSlice",
"{",
"makePkt",
"(",
"buf",
")",
"}",
",",
"nil",
"\n",
"}"
] | // OnGossip implements mesh.Gossiper.
// The buf is a single pkt. | [
"OnGossip",
"implements",
"mesh",
".",
"Gossiper",
".",
"The",
"buf",
"is",
"a",
"single",
"pkt",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/meshconn/peer.go#L164-L166 | test |
weaveworks/mesh | meshconn/peer.go | OnGossipBroadcast | func (p *Peer) OnGossipBroadcast(_ mesh.PeerName, buf []byte) (received mesh.GossipData, err error) {
pkt := makePkt(buf)
p.recv <- pkt // to ReadFrom
return pktSlice{pkt}, nil
} | go | func (p *Peer) OnGossipBroadcast(_ mesh.PeerName, buf []byte) (received mesh.GossipData, err error) {
pkt := makePkt(buf)
p.recv <- pkt // to ReadFrom
return pktSlice{pkt}, nil
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"OnGossipBroadcast",
"(",
"_",
"mesh",
".",
"PeerName",
",",
"buf",
"[",
"]",
"byte",
")",
"(",
"received",
"mesh",
".",
"GossipData",
",",
"err",
"error",
")",
"{",
"pkt",
":=",
"makePkt",
"(",
"buf",
")",
"\n",... | // OnGossipBroadcast implements mesh.Gossiper.
// The buf is a single pkt | [
"OnGossipBroadcast",
"implements",
"mesh",
".",
"Gossiper",
".",
"The",
"buf",
"is",
"a",
"single",
"pkt"
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/meshconn/peer.go#L170-L174 | test |
weaveworks/mesh | meshconn/peer.go | OnGossipUnicast | func (p *Peer) OnGossipUnicast(_ mesh.PeerName, buf []byte) error {
pkt := makePkt(buf)
p.recv <- pkt // to ReadFrom
return nil
} | go | func (p *Peer) OnGossipUnicast(_ mesh.PeerName, buf []byte) error {
pkt := makePkt(buf)
p.recv <- pkt // to ReadFrom
return nil
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"OnGossipUnicast",
"(",
"_",
"mesh",
".",
"PeerName",
",",
"buf",
"[",
"]",
"byte",
")",
"error",
"{",
"pkt",
":=",
"makePkt",
"(",
"buf",
")",
"\n",
"p",
".",
"recv",
"<-",
"pkt",
"\n",
"return",
"nil",
"\n",
... | // OnGossipUnicast implements mesh.Gossiper.
// The buf is a single pkt. | [
"OnGossipUnicast",
"implements",
"mesh",
".",
"Gossiper",
".",
"The",
"buf",
"is",
"a",
"single",
"pkt",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/meshconn/peer.go#L178-L182 | test |
weaveworks/mesh | _metcd/server.go | NewDefaultServer | func NewDefaultServer(
minPeerCount int,
terminatec <-chan struct{},
terminatedc chan<- error,
logger mesh.Logger,
) Server {
var (
peerName = mustPeerName()
nickName = mustHostname()
host = "0.0.0.0"
port = 6379
password = ""
channel = "metcd"
)
router := mesh.NewRouter(mesh.Config{
Host:... | go | func NewDefaultServer(
minPeerCount int,
terminatec <-chan struct{},
terminatedc chan<- error,
logger mesh.Logger,
) Server {
var (
peerName = mustPeerName()
nickName = mustHostname()
host = "0.0.0.0"
port = 6379
password = ""
channel = "metcd"
)
router := mesh.NewRouter(mesh.Config{
Host:... | [
"func",
"NewDefaultServer",
"(",
"minPeerCount",
"int",
",",
"terminatec",
"<-",
"chan",
"struct",
"{",
"}",
",",
"terminatedc",
"chan",
"<-",
"error",
",",
"logger",
"mesh",
".",
"Logger",
",",
")",
"Server",
"{",
"var",
"(",
"peerName",
"=",
"mustPeerNam... | // NewDefaultServer is like NewServer, but we take care of creating a
// mesh.Router and meshconn.Peer for you, with sane defaults. If you need more
// fine-grained control, create the components yourself and use NewServer. | [
"NewDefaultServer",
"is",
"like",
"NewServer",
"but",
"we",
"take",
"care",
"of",
"creating",
"a",
"mesh",
".",
"Router",
"and",
"meshconn",
".",
"Peer",
"for",
"you",
"with",
"sane",
"defaults",
".",
"If",
"you",
"need",
"more",
"fine",
"-",
"grained",
... | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/_metcd/server.go#L61-L97 | test |
weaveworks/mesh | peer_name_hash.go | PeerNameFromUserInput | func PeerNameFromUserInput(userInput string) (PeerName, error) {
// fixed-length identity
nameByteAry := sha256.Sum256([]byte(userInput))
return PeerNameFromBin(nameByteAry[:NameSize]), nil
} | go | func PeerNameFromUserInput(userInput string) (PeerName, error) {
// fixed-length identity
nameByteAry := sha256.Sum256([]byte(userInput))
return PeerNameFromBin(nameByteAry[:NameSize]), nil
} | [
"func",
"PeerNameFromUserInput",
"(",
"userInput",
"string",
")",
"(",
"PeerName",
",",
"error",
")",
"{",
"nameByteAry",
":=",
"sha256",
".",
"Sum256",
"(",
"[",
"]",
"byte",
"(",
"userInput",
")",
")",
"\n",
"return",
"PeerNameFromBin",
"(",
"nameByteAry",... | // PeerNameFromUserInput parses PeerName from a user-provided string. | [
"PeerNameFromUserInput",
"parses",
"PeerName",
"from",
"a",
"user",
"-",
"provided",
"string",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/peer_name_hash.go#L27-L31 | test |
weaveworks/mesh | peer_name_hash.go | bytes | func (name PeerName) bytes() []byte {
res, err := hex.DecodeString(string(name))
if err != nil {
panic("unable to decode name to bytes: " + name)
}
return res
} | go | func (name PeerName) bytes() []byte {
res, err := hex.DecodeString(string(name))
if err != nil {
panic("unable to decode name to bytes: " + name)
}
return res
} | [
"func",
"(",
"name",
"PeerName",
")",
"bytes",
"(",
")",
"[",
"]",
"byte",
"{",
"res",
",",
"err",
":=",
"hex",
".",
"DecodeString",
"(",
"string",
"(",
"name",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"\"unable to decode name to ... | // bytes encodes PeerName as a byte slice. | [
"bytes",
"encodes",
"PeerName",
"as",
"a",
"byte",
"slice",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/peer_name_hash.go#L47-L53 | test |
weaveworks/mesh | router.go | NewRouter | func NewRouter(config Config, name PeerName, nickName string, overlay Overlay, logger Logger) (*Router, error) {
router := &Router{Config: config, gossipChannels: make(gossipChannels)}
if overlay == nil {
overlay = NullOverlay{}
}
router.Overlay = overlay
router.Ourself = newLocalPeer(name, nickName, router)
... | go | func NewRouter(config Config, name PeerName, nickName string, overlay Overlay, logger Logger) (*Router, error) {
router := &Router{Config: config, gossipChannels: make(gossipChannels)}
if overlay == nil {
overlay = NullOverlay{}
}
router.Overlay = overlay
router.Ourself = newLocalPeer(name, nickName, router)
... | [
"func",
"NewRouter",
"(",
"config",
"Config",
",",
"name",
"PeerName",
",",
"nickName",
"string",
",",
"overlay",
"Overlay",
",",
"logger",
"Logger",
")",
"(",
"*",
"Router",
",",
"error",
")",
"{",
"router",
":=",
"&",
"Router",
"{",
"Config",
":",
"c... | // NewRouter returns a new router. It must be started. | [
"NewRouter",
"returns",
"a",
"new",
"router",
".",
"It",
"must",
"be",
"started",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/router.go#L59-L82 | test |
weaveworks/mesh | router.go | sendAllGossip | func (router *Router) sendAllGossip() {
for channel := range router.gossipChannelSet() {
if gossip := channel.gossiper.Gossip(); gossip != nil {
channel.Send(gossip)
}
}
} | go | func (router *Router) sendAllGossip() {
for channel := range router.gossipChannelSet() {
if gossip := channel.gossiper.Gossip(); gossip != nil {
channel.Send(gossip)
}
}
} | [
"func",
"(",
"router",
"*",
"Router",
")",
"sendAllGossip",
"(",
")",
"{",
"for",
"channel",
":=",
"range",
"router",
".",
"gossipChannelSet",
"(",
")",
"{",
"if",
"gossip",
":=",
"channel",
".",
"gossiper",
".",
"Gossip",
"(",
")",
";",
"gossip",
"!="... | // Relay all pending gossip data for each channel via random neighbours. | [
"Relay",
"all",
"pending",
"gossip",
"data",
"for",
"each",
"channel",
"via",
"random",
"neighbours",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/router.go#L196-L202 | test |
weaveworks/mesh | router.go | sendAllGossipDown | func (router *Router) sendAllGossipDown(conn Connection) {
for channel := range router.gossipChannelSet() {
if gossip := channel.gossiper.Gossip(); gossip != nil {
channel.SendDown(conn, gossip)
}
}
} | go | func (router *Router) sendAllGossipDown(conn Connection) {
for channel := range router.gossipChannelSet() {
if gossip := channel.gossiper.Gossip(); gossip != nil {
channel.SendDown(conn, gossip)
}
}
} | [
"func",
"(",
"router",
"*",
"Router",
")",
"sendAllGossipDown",
"(",
"conn",
"Connection",
")",
"{",
"for",
"channel",
":=",
"range",
"router",
".",
"gossipChannelSet",
"(",
")",
"{",
"if",
"gossip",
":=",
"channel",
".",
"gossiper",
".",
"Gossip",
"(",
... | // Relay all pending gossip data for each channel via conn. | [
"Relay",
"all",
"pending",
"gossip",
"data",
"for",
"each",
"channel",
"via",
"conn",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/router.go#L205-L211 | test |
weaveworks/mesh | router.go | broadcastTopologyUpdate | func (router *Router) broadcastTopologyUpdate(update []*Peer) {
names := make(peerNameSet)
for _, p := range update {
names[p.Name] = struct{}{}
}
router.topologyGossip.GossipBroadcast(&topologyGossipData{peers: router.Peers, update: names})
} | go | func (router *Router) broadcastTopologyUpdate(update []*Peer) {
names := make(peerNameSet)
for _, p := range update {
names[p.Name] = struct{}{}
}
router.topologyGossip.GossipBroadcast(&topologyGossipData{peers: router.Peers, update: names})
} | [
"func",
"(",
"router",
"*",
"Router",
")",
"broadcastTopologyUpdate",
"(",
"update",
"[",
"]",
"*",
"Peer",
")",
"{",
"names",
":=",
"make",
"(",
"peerNameSet",
")",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"update",
"{",
"names",
"[",
"p",
".",
... | // BroadcastTopologyUpdate is invoked whenever there is a change to the mesh
// topology, and broadcasts the new set of peers to the mesh. | [
"BroadcastTopologyUpdate",
"is",
"invoked",
"whenever",
"there",
"is",
"a",
"change",
"to",
"the",
"mesh",
"topology",
"and",
"broadcasts",
"the",
"new",
"set",
"of",
"peers",
"to",
"the",
"mesh",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/router.go#L224-L230 | test |
weaveworks/mesh | router.go | OnGossipUnicast | func (router *Router) OnGossipUnicast(sender PeerName, msg []byte) error {
return fmt.Errorf("unexpected topology gossip unicast: %v", msg)
} | go | func (router *Router) OnGossipUnicast(sender PeerName, msg []byte) error {
return fmt.Errorf("unexpected topology gossip unicast: %v", msg)
} | [
"func",
"(",
"router",
"*",
"Router",
")",
"OnGossipUnicast",
"(",
"sender",
"PeerName",
",",
"msg",
"[",
"]",
"byte",
")",
"error",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"unexpected topology gossip unicast: %v\"",
",",
"msg",
")",
"\n",
"}"
] | // OnGossipUnicast implements Gossiper, but always returns an error, as a
// router should only receive gossip broadcasts of TopologyGossipData. | [
"OnGossipUnicast",
"implements",
"Gossiper",
"but",
"always",
"returns",
"an",
"error",
"as",
"a",
"router",
"should",
"only",
"receive",
"gossip",
"broadcasts",
"of",
"TopologyGossipData",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/router.go#L234-L236 | test |
weaveworks/mesh | router.go | OnGossipBroadcast | func (router *Router) OnGossipBroadcast(_ PeerName, update []byte) (GossipData, error) {
origUpdate, _, err := router.applyTopologyUpdate(update)
if err != nil || len(origUpdate) == 0 {
return nil, err
}
return &topologyGossipData{peers: router.Peers, update: origUpdate}, nil
} | go | func (router *Router) OnGossipBroadcast(_ PeerName, update []byte) (GossipData, error) {
origUpdate, _, err := router.applyTopologyUpdate(update)
if err != nil || len(origUpdate) == 0 {
return nil, err
}
return &topologyGossipData{peers: router.Peers, update: origUpdate}, nil
} | [
"func",
"(",
"router",
"*",
"Router",
")",
"OnGossipBroadcast",
"(",
"_",
"PeerName",
",",
"update",
"[",
"]",
"byte",
")",
"(",
"GossipData",
",",
"error",
")",
"{",
"origUpdate",
",",
"_",
",",
"err",
":=",
"router",
".",
"applyTopologyUpdate",
"(",
... | // OnGossipBroadcast receives broadcasts of TopologyGossipData.
// It returns the received update unchanged. | [
"OnGossipBroadcast",
"receives",
"broadcasts",
"of",
"TopologyGossipData",
".",
"It",
"returns",
"the",
"received",
"update",
"unchanged",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/router.go#L240-L246 | test |
weaveworks/mesh | router.go | Gossip | func (router *Router) Gossip() GossipData {
return &topologyGossipData{peers: router.Peers, update: router.Peers.names()}
} | go | func (router *Router) Gossip() GossipData {
return &topologyGossipData{peers: router.Peers, update: router.Peers.names()}
} | [
"func",
"(",
"router",
"*",
"Router",
")",
"Gossip",
"(",
")",
"GossipData",
"{",
"return",
"&",
"topologyGossipData",
"{",
"peers",
":",
"router",
".",
"Peers",
",",
"update",
":",
"router",
".",
"Peers",
".",
"names",
"(",
")",
"}",
"\n",
"}"
] | // Gossip yields the current topology as GossipData. | [
"Gossip",
"yields",
"the",
"current",
"topology",
"as",
"GossipData",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/router.go#L249-L251 | test |
weaveworks/mesh | router.go | OnGossip | func (router *Router) OnGossip(update []byte) (GossipData, error) {
_, newUpdate, err := router.applyTopologyUpdate(update)
if err != nil || len(newUpdate) == 0 {
return nil, err
}
return &topologyGossipData{peers: router.Peers, update: newUpdate}, nil
} | go | func (router *Router) OnGossip(update []byte) (GossipData, error) {
_, newUpdate, err := router.applyTopologyUpdate(update)
if err != nil || len(newUpdate) == 0 {
return nil, err
}
return &topologyGossipData{peers: router.Peers, update: newUpdate}, nil
} | [
"func",
"(",
"router",
"*",
"Router",
")",
"OnGossip",
"(",
"update",
"[",
"]",
"byte",
")",
"(",
"GossipData",
",",
"error",
")",
"{",
"_",
",",
"newUpdate",
",",
"err",
":=",
"router",
".",
"applyTopologyUpdate",
"(",
"update",
")",
"\n",
"if",
"er... | // OnGossip receives broadcasts of TopologyGossipData.
// It returns an "improved" version of the received update.
// See peers.ApplyUpdate. | [
"OnGossip",
"receives",
"broadcasts",
"of",
"TopologyGossipData",
".",
"It",
"returns",
"an",
"improved",
"version",
"of",
"the",
"received",
"update",
".",
"See",
"peers",
".",
"ApplyUpdate",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/router.go#L256-L262 | test |
weaveworks/mesh | router.go | Encode | func (d *topologyGossipData) Encode() [][]byte {
return [][]byte{d.peers.encodePeers(d.update)}
} | go | func (d *topologyGossipData) Encode() [][]byte {
return [][]byte{d.peers.encodePeers(d.update)}
} | [
"func",
"(",
"d",
"*",
"topologyGossipData",
")",
"Encode",
"(",
")",
"[",
"]",
"[",
"]",
"byte",
"{",
"return",
"[",
"]",
"[",
"]",
"byte",
"{",
"d",
".",
"peers",
".",
"encodePeers",
"(",
"d",
".",
"update",
")",
"}",
"\n",
"}"
] | // Encode implements GossipData. | [
"Encode",
"implements",
"GossipData",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/router.go#L310-L312 | test |
weaveworks/mesh | examples/increment-only-counter/state.go | newState | func newState(self mesh.PeerName) *state {
return &state{
set: map[mesh.PeerName]int{},
self: self,
}
} | go | func newState(self mesh.PeerName) *state {
return &state{
set: map[mesh.PeerName]int{},
self: self,
}
} | [
"func",
"newState",
"(",
"self",
"mesh",
".",
"PeerName",
")",
"*",
"state",
"{",
"return",
"&",
"state",
"{",
"set",
":",
"map",
"[",
"mesh",
".",
"PeerName",
"]",
"int",
"{",
"}",
",",
"self",
":",
"self",
",",
"}",
"\n",
"}"
] | // Construct an empty state object, ready to receive updates.
// This is suitable to use at program start.
// Other peers will populate us with data. | [
"Construct",
"an",
"empty",
"state",
"object",
"ready",
"to",
"receive",
"updates",
".",
"This",
"is",
"suitable",
"to",
"use",
"at",
"program",
"start",
".",
"Other",
"peers",
"will",
"populate",
"us",
"with",
"data",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/examples/increment-only-counter/state.go#L25-L30 | test |
weaveworks/mesh | examples/increment-only-counter/state.go | Merge | func (st *state) Merge(other mesh.GossipData) (complete mesh.GossipData) {
return st.mergeComplete(other.(*state).copy().set)
} | go | func (st *state) Merge(other mesh.GossipData) (complete mesh.GossipData) {
return st.mergeComplete(other.(*state).copy().set)
} | [
"func",
"(",
"st",
"*",
"state",
")",
"Merge",
"(",
"other",
"mesh",
".",
"GossipData",
")",
"(",
"complete",
"mesh",
".",
"GossipData",
")",
"{",
"return",
"st",
".",
"mergeComplete",
"(",
"other",
".",
"(",
"*",
"state",
")",
".",
"copy",
"(",
")... | // Merge merges the other GossipData into this one,
// and returns our resulting, complete state. | [
"Merge",
"merges",
"the",
"other",
"GossipData",
"into",
"this",
"one",
"and",
"returns",
"our",
"resulting",
"complete",
"state",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/examples/increment-only-counter/state.go#L73-L75 | test |
weaveworks/mesh | examples/increment-only-counter/state.go | mergeReceived | func (st *state) mergeReceived(set map[mesh.PeerName]int) (received mesh.GossipData) {
st.mtx.Lock()
defer st.mtx.Unlock()
for peer, v := range set {
if v <= st.set[peer] {
delete(set, peer) // optimization: make the forwarded data smaller
continue
}
st.set[peer] = v
}
return &state{
set: set, // a... | go | func (st *state) mergeReceived(set map[mesh.PeerName]int) (received mesh.GossipData) {
st.mtx.Lock()
defer st.mtx.Unlock()
for peer, v := range set {
if v <= st.set[peer] {
delete(set, peer) // optimization: make the forwarded data smaller
continue
}
st.set[peer] = v
}
return &state{
set: set, // a... | [
"func",
"(",
"st",
"*",
"state",
")",
"mergeReceived",
"(",
"set",
"map",
"[",
"mesh",
".",
"PeerName",
"]",
"int",
")",
"(",
"received",
"mesh",
".",
"GossipData",
")",
"{",
"st",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"st",
".",
"mtx... | // Merge the set into our state, abiding increment-only semantics.
// Return a non-nil mesh.GossipData representation of the received set. | [
"Merge",
"the",
"set",
"into",
"our",
"state",
"abiding",
"increment",
"-",
"only",
"semantics",
".",
"Return",
"a",
"non",
"-",
"nil",
"mesh",
".",
"GossipData",
"representation",
"of",
"the",
"received",
"set",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/examples/increment-only-counter/state.go#L79-L94 | test |
weaveworks/mesh | examples/increment-only-counter/state.go | mergeComplete | func (st *state) mergeComplete(set map[mesh.PeerName]int) (complete mesh.GossipData) {
st.mtx.Lock()
defer st.mtx.Unlock()
for peer, v := range set {
if v > st.set[peer] {
st.set[peer] = v
}
}
return &state{
set: st.set, // n.b. can't .copy() due to lock contention
}
} | go | func (st *state) mergeComplete(set map[mesh.PeerName]int) (complete mesh.GossipData) {
st.mtx.Lock()
defer st.mtx.Unlock()
for peer, v := range set {
if v > st.set[peer] {
st.set[peer] = v
}
}
return &state{
set: st.set, // n.b. can't .copy() due to lock contention
}
} | [
"func",
"(",
"st",
"*",
"state",
")",
"mergeComplete",
"(",
"set",
"map",
"[",
"mesh",
".",
"PeerName",
"]",
"int",
")",
"(",
"complete",
"mesh",
".",
"GossipData",
")",
"{",
"st",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"st",
".",
"mtx... | // Merge the set into our state, abiding increment-only semantics.
// Return our resulting, complete state. | [
"Merge",
"the",
"set",
"into",
"our",
"state",
"abiding",
"increment",
"-",
"only",
"semantics",
".",
"Return",
"our",
"resulting",
"complete",
"state",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/examples/increment-only-counter/state.go#L120-L133 | test |
weaveworks/mesh | surrogate_gossiper.go | OnGossipBroadcast | func (*surrogateGossiper) OnGossipBroadcast(_ PeerName, update []byte) (GossipData, error) {
return newSurrogateGossipData(update), nil
} | go | func (*surrogateGossiper) OnGossipBroadcast(_ PeerName, update []byte) (GossipData, error) {
return newSurrogateGossipData(update), nil
} | [
"func",
"(",
"*",
"surrogateGossiper",
")",
"OnGossipBroadcast",
"(",
"_",
"PeerName",
",",
"update",
"[",
"]",
"byte",
")",
"(",
"GossipData",
",",
"error",
")",
"{",
"return",
"newSurrogateGossipData",
"(",
"update",
")",
",",
"nil",
"\n",
"}"
] | // OnGossipBroadcast implements Gossiper. | [
"OnGossipBroadcast",
"implements",
"Gossiper",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/surrogate_gossiper.go#L33-L35 | test |
weaveworks/mesh | surrogate_gossiper.go | OnGossip | func (s *surrogateGossiper) OnGossip(update []byte) (GossipData, error) {
hash := fnv.New64a()
_, _ = hash.Write(update)
updateHash := hash.Sum64()
s.Lock()
defer s.Unlock()
for _, p := range s.prevUpdates {
if updateHash == p.hash && bytes.Equal(update, p.update) {
return nil, nil
}
}
// Delete anything... | go | func (s *surrogateGossiper) OnGossip(update []byte) (GossipData, error) {
hash := fnv.New64a()
_, _ = hash.Write(update)
updateHash := hash.Sum64()
s.Lock()
defer s.Unlock()
for _, p := range s.prevUpdates {
if updateHash == p.hash && bytes.Equal(update, p.update) {
return nil, nil
}
}
// Delete anything... | [
"func",
"(",
"s",
"*",
"surrogateGossiper",
")",
"OnGossip",
"(",
"update",
"[",
"]",
"byte",
")",
"(",
"GossipData",
",",
"error",
")",
"{",
"hash",
":=",
"fnv",
".",
"New64a",
"(",
")",
"\n",
"_",
",",
"_",
"=",
"hash",
".",
"Write",
"(",
"upda... | // OnGossip should return "everything new I've just learnt".
// surrogateGossiper doesn't understand the content of messages, but it can eliminate simple duplicates | [
"OnGossip",
"should",
"return",
"everything",
"new",
"I",
"ve",
"just",
"learnt",
".",
"surrogateGossiper",
"doesn",
"t",
"understand",
"the",
"content",
"of",
"messages",
"but",
"it",
"can",
"eliminate",
"simple",
"duplicates"
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/surrogate_gossiper.go#L44-L69 | test |
weaveworks/mesh | protocol_crypto.go | generateKeyPair | func generateKeyPair() (publicKey, privateKey *[32]byte, err error) {
return box.GenerateKey(rand.Reader)
} | go | func generateKeyPair() (publicKey, privateKey *[32]byte, err error) {
return box.GenerateKey(rand.Reader)
} | [
"func",
"generateKeyPair",
"(",
")",
"(",
"publicKey",
",",
"privateKey",
"*",
"[",
"32",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"return",
"box",
".",
"GenerateKey",
"(",
"rand",
".",
"Reader",
")",
"\n",
"}"
] | // GenerateKeyPair is used during encrypted protocol introduction. | [
"GenerateKeyPair",
"is",
"used",
"during",
"encrypted",
"protocol",
"introduction",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/protocol_crypto.go#L22-L24 | test |
weaveworks/mesh | protocol_crypto.go | formSessionKey | func formSessionKey(remotePublicKey, localPrivateKey *[32]byte, secretKey []byte) *[32]byte {
var sharedKey [32]byte
box.Precompute(&sharedKey, remotePublicKey, localPrivateKey)
sharedKeySlice := sharedKey[:]
sharedKeySlice = append(sharedKeySlice, secretKey...)
sessionKey := sha256.Sum256(sharedKeySlice)
return ... | go | func formSessionKey(remotePublicKey, localPrivateKey *[32]byte, secretKey []byte) *[32]byte {
var sharedKey [32]byte
box.Precompute(&sharedKey, remotePublicKey, localPrivateKey)
sharedKeySlice := sharedKey[:]
sharedKeySlice = append(sharedKeySlice, secretKey...)
sessionKey := sha256.Sum256(sharedKeySlice)
return ... | [
"func",
"formSessionKey",
"(",
"remotePublicKey",
",",
"localPrivateKey",
"*",
"[",
"32",
"]",
"byte",
",",
"secretKey",
"[",
"]",
"byte",
")",
"*",
"[",
"32",
"]",
"byte",
"{",
"var",
"sharedKey",
"[",
"32",
"]",
"byte",
"\n",
"box",
".",
"Precompute"... | // FormSessionKey is used during encrypted protocol introduction. | [
"FormSessionKey",
"is",
"used",
"during",
"encrypted",
"protocol",
"introduction",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/protocol_crypto.go#L27-L34 | test |
weaveworks/mesh | protocol_crypto.go | newTCPCryptoState | func newTCPCryptoState(sessionKey *[32]byte, outbound bool) *tcpCryptoState {
s := &tcpCryptoState{sessionKey: sessionKey}
if outbound {
s.nonce[0] |= (1 << 7)
}
s.nonce[0] |= (1 << 6)
return s
} | go | func newTCPCryptoState(sessionKey *[32]byte, outbound bool) *tcpCryptoState {
s := &tcpCryptoState{sessionKey: sessionKey}
if outbound {
s.nonce[0] |= (1 << 7)
}
s.nonce[0] |= (1 << 6)
return s
} | [
"func",
"newTCPCryptoState",
"(",
"sessionKey",
"*",
"[",
"32",
"]",
"byte",
",",
"outbound",
"bool",
")",
"*",
"tcpCryptoState",
"{",
"s",
":=",
"&",
"tcpCryptoState",
"{",
"sessionKey",
":",
"sessionKey",
"}",
"\n",
"if",
"outbound",
"{",
"s",
".",
"no... | // NewTCPCryptoState returns a valid TCPCryptoState. | [
"NewTCPCryptoState",
"returns",
"a",
"valid",
"TCPCryptoState",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/protocol_crypto.go#L55-L62 | test |
weaveworks/mesh | protocol_crypto.go | Send | func (sender *gobTCPSender) Send(msg []byte) error {
return sender.encoder.Encode(msg)
} | go | func (sender *gobTCPSender) Send(msg []byte) error {
return sender.encoder.Encode(msg)
} | [
"func",
"(",
"sender",
"*",
"gobTCPSender",
")",
"Send",
"(",
"msg",
"[",
"]",
"byte",
")",
"error",
"{",
"return",
"sender",
".",
"encoder",
".",
"Encode",
"(",
"msg",
")",
"\n",
"}"
] | // Send implements TCPSender by encoding the msg. | [
"Send",
"implements",
"TCPSender",
"by",
"encoding",
"the",
"msg",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/protocol_crypto.go#L85-L87 | test |
weaveworks/mesh | protocol_crypto.go | Send | func (sender *lengthPrefixTCPSender) Send(msg []byte) error {
l := len(msg)
if l > maxTCPMsgSize {
return fmt.Errorf("outgoing message exceeds maximum size: %d > %d", l, maxTCPMsgSize)
}
// We copy the message so we can send it in a single Write
// operation, thus making this thread-safe without locking.
prefix... | go | func (sender *lengthPrefixTCPSender) Send(msg []byte) error {
l := len(msg)
if l > maxTCPMsgSize {
return fmt.Errorf("outgoing message exceeds maximum size: %d > %d", l, maxTCPMsgSize)
}
// We copy the message so we can send it in a single Write
// operation, thus making this thread-safe without locking.
prefix... | [
"func",
"(",
"sender",
"*",
"lengthPrefixTCPSender",
")",
"Send",
"(",
"msg",
"[",
"]",
"byte",
")",
"error",
"{",
"l",
":=",
"len",
"(",
"msg",
")",
"\n",
"if",
"l",
">",
"maxTCPMsgSize",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"outgoing message e... | // Send implements TCPSender by writing the size of the msg as a big-endian
// uint32 before the msg. msgs larger than MaxTCPMsgSize are rejected. | [
"Send",
"implements",
"TCPSender",
"by",
"writing",
"the",
"size",
"of",
"the",
"msg",
"as",
"a",
"big",
"-",
"endian",
"uint32",
"before",
"the",
"msg",
".",
"msgs",
"larger",
"than",
"MaxTCPMsgSize",
"are",
"rejected",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/protocol_crypto.go#L100-L112 | test |
weaveworks/mesh | protocol_crypto.go | Send | func (sender *encryptedTCPSender) Send(msg []byte) error {
sender.Lock()
defer sender.Unlock()
encodedMsg := secretbox.Seal(nil, msg, &sender.state.nonce, sender.state.sessionKey)
sender.state.advance()
return sender.sender.Send(encodedMsg)
} | go | func (sender *encryptedTCPSender) Send(msg []byte) error {
sender.Lock()
defer sender.Unlock()
encodedMsg := secretbox.Seal(nil, msg, &sender.state.nonce, sender.state.sessionKey)
sender.state.advance()
return sender.sender.Send(encodedMsg)
} | [
"func",
"(",
"sender",
"*",
"encryptedTCPSender",
")",
"Send",
"(",
"msg",
"[",
"]",
"byte",
")",
"error",
"{",
"sender",
".",
"Lock",
"(",
")",
"\n",
"defer",
"sender",
".",
"Unlock",
"(",
")",
"\n",
"encodedMsg",
":=",
"secretbox",
".",
"Seal",
"("... | // Send implements TCPSender by sealing and sending the msg as-is. | [
"Send",
"implements",
"TCPSender",
"by",
"sealing",
"and",
"sending",
"the",
"msg",
"as",
"-",
"is",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/protocol_crypto.go#L126-L132 | test |
weaveworks/mesh | protocol_crypto.go | Receive | func (receiver *gobTCPReceiver) Receive() ([]byte, error) {
var msg []byte
err := receiver.decoder.Decode(&msg)
return msg, err
} | go | func (receiver *gobTCPReceiver) Receive() ([]byte, error) {
var msg []byte
err := receiver.decoder.Decode(&msg)
return msg, err
} | [
"func",
"(",
"receiver",
"*",
"gobTCPReceiver",
")",
"Receive",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"msg",
"[",
"]",
"byte",
"\n",
"err",
":=",
"receiver",
".",
"decoder",
".",
"Decode",
"(",
"&",
"msg",
")",
"\n",
"re... | // Receive implements TCPReciever by Gob decoding into a byte slice directly. | [
"Receive",
"implements",
"TCPReciever",
"by",
"Gob",
"decoding",
"into",
"a",
"byte",
"slice",
"directly",
"."
] | 512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39 | https://github.com/weaveworks/mesh/blob/512bdb7b3cb7b2c939fcd0ee434d48b6732ecc39/protocol_crypto.go#L150-L154 | test |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.