id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
163,600 | btcsuite/btcd | rpcwebsocket.go | handleNotifyReceived | func handleNotifyReceived(wsc *wsClient, icmd interface{}) (interface{}, error) {
cmd, ok := icmd.(*btcjson.NotifyReceivedCmd)
if !ok {
return nil, btcjson.ErrRPCInternal
}
// Decode addresses to validate input, but the strings slice is used
// directly if these are all ok.
err := checkAddressValidity(cmd.Addr... | go | func handleNotifyReceived(wsc *wsClient, icmd interface{}) (interface{}, error) {
cmd, ok := icmd.(*btcjson.NotifyReceivedCmd)
if !ok {
return nil, btcjson.ErrRPCInternal
}
// Decode addresses to validate input, but the strings slice is used
// directly if these are all ok.
err := checkAddressValidity(cmd.Addr... | [
"func",
"handleNotifyReceived",
"(",
"wsc",
"*",
"wsClient",
",",
"icmd",
"interface",
"{",
"}",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"cmd",
",",
"ok",
":=",
"icmd",
".",
"(",
"*",
"btcjson",
".",
"NotifyReceivedCmd",
")",
"\n",
"... | // handleNotifyReceived implements the notifyreceived command extension for
// websocket connections. | [
"handleNotifyReceived",
"implements",
"the",
"notifyreceived",
"command",
"extension",
"for",
"websocket",
"connections",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcwebsocket.go#L1887-L1902 |
163,601 | btcsuite/btcd | rpcwebsocket.go | handleStopNotifySpent | func handleStopNotifySpent(wsc *wsClient, icmd interface{}) (interface{}, error) {
cmd, ok := icmd.(*btcjson.StopNotifySpentCmd)
if !ok {
return nil, btcjson.ErrRPCInternal
}
outpoints, err := deserializeOutpoints(cmd.OutPoints)
if err != nil {
return nil, err
}
for _, outpoint := range outpoints {
wsc.s... | go | func handleStopNotifySpent(wsc *wsClient, icmd interface{}) (interface{}, error) {
cmd, ok := icmd.(*btcjson.StopNotifySpentCmd)
if !ok {
return nil, btcjson.ErrRPCInternal
}
outpoints, err := deserializeOutpoints(cmd.OutPoints)
if err != nil {
return nil, err
}
for _, outpoint := range outpoints {
wsc.s... | [
"func",
"handleStopNotifySpent",
"(",
"wsc",
"*",
"wsClient",
",",
"icmd",
"interface",
"{",
"}",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"cmd",
",",
"ok",
":=",
"icmd",
".",
"(",
"*",
"btcjson",
".",
"StopNotifySpentCmd",
")",
"\n",
... | // handleStopNotifySpent implements the stopnotifyspent command extension for
// websocket connections. | [
"handleStopNotifySpent",
"implements",
"the",
"stopnotifyspent",
"command",
"extension",
"for",
"websocket",
"connections",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcwebsocket.go#L1906-L1922 |
163,602 | btcsuite/btcd | rpcwebsocket.go | handleStopNotifyReceived | func handleStopNotifyReceived(wsc *wsClient, icmd interface{}) (interface{}, error) {
cmd, ok := icmd.(*btcjson.StopNotifyReceivedCmd)
if !ok {
return nil, btcjson.ErrRPCInternal
}
// Decode addresses to validate input, but the strings slice is used
// directly if these are all ok.
err := checkAddressValidity(... | go | func handleStopNotifyReceived(wsc *wsClient, icmd interface{}) (interface{}, error) {
cmd, ok := icmd.(*btcjson.StopNotifyReceivedCmd)
if !ok {
return nil, btcjson.ErrRPCInternal
}
// Decode addresses to validate input, but the strings slice is used
// directly if these are all ok.
err := checkAddressValidity(... | [
"func",
"handleStopNotifyReceived",
"(",
"wsc",
"*",
"wsClient",
",",
"icmd",
"interface",
"{",
"}",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"cmd",
",",
"ok",
":=",
"icmd",
".",
"(",
"*",
"btcjson",
".",
"StopNotifyReceivedCmd",
")",
"... | // handleStopNotifyReceived implements the stopnotifyreceived command extension
// for websocket connections. | [
"handleStopNotifyReceived",
"implements",
"the",
"stopnotifyreceived",
"command",
"extension",
"for",
"websocket",
"connections",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcwebsocket.go#L1926-L1944 |
163,603 | btcsuite/btcd | rpcwebsocket.go | checkAddressValidity | func checkAddressValidity(addrs []string, params *chaincfg.Params) error {
for _, addr := range addrs {
_, err := btcutil.DecodeAddress(addr, params)
if err != nil {
return &btcjson.RPCError{
Code: btcjson.ErrRPCInvalidAddressOrKey,
Message: fmt.Sprintf("Invalid address or key: %v",
addr),
}
}... | go | func checkAddressValidity(addrs []string, params *chaincfg.Params) error {
for _, addr := range addrs {
_, err := btcutil.DecodeAddress(addr, params)
if err != nil {
return &btcjson.RPCError{
Code: btcjson.ErrRPCInvalidAddressOrKey,
Message: fmt.Sprintf("Invalid address or key: %v",
addr),
}
}... | [
"func",
"checkAddressValidity",
"(",
"addrs",
"[",
"]",
"string",
",",
"params",
"*",
"chaincfg",
".",
"Params",
")",
"error",
"{",
"for",
"_",
",",
"addr",
":=",
"range",
"addrs",
"{",
"_",
",",
"err",
":=",
"btcutil",
".",
"DecodeAddress",
"(",
"addr... | // checkAddressValidity checks the validity of each address in the passed
// string slice. It does this by attempting to decode each address using the
// current active network parameters. If any single address fails to decode
// properly, the function returns an error. Otherwise, nil is returned. | [
"checkAddressValidity",
"checks",
"the",
"validity",
"of",
"each",
"address",
"in",
"the",
"passed",
"string",
"slice",
".",
"It",
"does",
"this",
"by",
"attempting",
"to",
"decode",
"each",
"address",
"using",
"the",
"current",
"active",
"network",
"parameters"... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcwebsocket.go#L1950-L1962 |
163,604 | btcsuite/btcd | rpcwebsocket.go | deserializeOutpoints | func deserializeOutpoints(serializedOuts []btcjson.OutPoint) ([]*wire.OutPoint, error) {
outpoints := make([]*wire.OutPoint, 0, len(serializedOuts))
for i := range serializedOuts {
blockHash, err := chainhash.NewHashFromStr(serializedOuts[i].Hash)
if err != nil {
return nil, rpcDecodeHexError(serializedOuts[i]... | go | func deserializeOutpoints(serializedOuts []btcjson.OutPoint) ([]*wire.OutPoint, error) {
outpoints := make([]*wire.OutPoint, 0, len(serializedOuts))
for i := range serializedOuts {
blockHash, err := chainhash.NewHashFromStr(serializedOuts[i].Hash)
if err != nil {
return nil, rpcDecodeHexError(serializedOuts[i]... | [
"func",
"deserializeOutpoints",
"(",
"serializedOuts",
"[",
"]",
"btcjson",
".",
"OutPoint",
")",
"(",
"[",
"]",
"*",
"wire",
".",
"OutPoint",
",",
"error",
")",
"{",
"outpoints",
":=",
"make",
"(",
"[",
"]",
"*",
"wire",
".",
"OutPoint",
",",
"0",
"... | // deserializeOutpoints deserializes each serialized outpoint. | [
"deserializeOutpoints",
"deserializes",
"each",
"serialized",
"outpoint",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcwebsocket.go#L1965-L1977 |
163,605 | btcsuite/btcd | rpcwebsocket.go | unspentSlice | func (r *rescanKeys) unspentSlice() []*wire.OutPoint {
ops := make([]*wire.OutPoint, 0, len(r.unspent))
for op := range r.unspent {
opCopy := op
ops = append(ops, &opCopy)
}
return ops
} | go | func (r *rescanKeys) unspentSlice() []*wire.OutPoint {
ops := make([]*wire.OutPoint, 0, len(r.unspent))
for op := range r.unspent {
opCopy := op
ops = append(ops, &opCopy)
}
return ops
} | [
"func",
"(",
"r",
"*",
"rescanKeys",
")",
"unspentSlice",
"(",
")",
"[",
"]",
"*",
"wire",
".",
"OutPoint",
"{",
"ops",
":=",
"make",
"(",
"[",
"]",
"*",
"wire",
".",
"OutPoint",
",",
"0",
",",
"len",
"(",
"r",
".",
"unspent",
")",
")",
"\n",
... | // unspentSlice returns a slice of currently-unspent outpoints for the rescan
// lookup keys. This is primarily intended to be used to register outpoints
// for continuous notifications after a rescan has completed. | [
"unspentSlice",
"returns",
"a",
"slice",
"of",
"currently",
"-",
"unspent",
"outpoints",
"for",
"the",
"rescan",
"lookup",
"keys",
".",
"This",
"is",
"primarily",
"intended",
"to",
"be",
"used",
"to",
"register",
"outpoints",
"for",
"continuous",
"notifications"... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcwebsocket.go#L1987-L1994 |
163,606 | btcsuite/btcd | rpcwebsocket.go | recoverFromReorg | func recoverFromReorg(chain *blockchain.BlockChain, minBlock, maxBlock int32,
lastBlock *chainhash.Hash) ([]chainhash.Hash, error) {
hashList, err := chain.HeightRange(minBlock, maxBlock)
if err != nil {
rpcsLog.Errorf("Error looking up block range: %v", err)
return nil, &btcjson.RPCError{
Code: btcjson.E... | go | func recoverFromReorg(chain *blockchain.BlockChain, minBlock, maxBlock int32,
lastBlock *chainhash.Hash) ([]chainhash.Hash, error) {
hashList, err := chain.HeightRange(minBlock, maxBlock)
if err != nil {
rpcsLog.Errorf("Error looking up block range: %v", err)
return nil, &btcjson.RPCError{
Code: btcjson.E... | [
"func",
"recoverFromReorg",
"(",
"chain",
"*",
"blockchain",
".",
"BlockChain",
",",
"minBlock",
",",
"maxBlock",
"int32",
",",
"lastBlock",
"*",
"chainhash",
".",
"Hash",
")",
"(",
"[",
"]",
"chainhash",
".",
"Hash",
",",
"error",
")",
"{",
"hashList",
... | // recoverFromReorg attempts to recover from a detected reorganize during a
// rescan. It fetches a new range of block shas from the database and
// verifies that the new range of blocks is on the same fork as a previous
// range of blocks. If this condition does not hold true, the JSON-RPC error
// for an unrecovera... | [
"recoverFromReorg",
"attempts",
"to",
"recover",
"from",
"a",
"detected",
"reorganize",
"during",
"a",
"rescan",
".",
"It",
"fetches",
"a",
"new",
"range",
"of",
"block",
"shas",
"from",
"the",
"database",
"and",
"verifies",
"that",
"the",
"new",
"range",
"o... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcwebsocket.go#L2281-L2310 |
163,607 | btcsuite/btcd | rpcwebsocket.go | descendantBlock | func descendantBlock(prevHash *chainhash.Hash, curBlock *btcutil.Block) error {
curHash := &curBlock.MsgBlock().Header.PrevBlock
if !prevHash.IsEqual(curHash) {
rpcsLog.Errorf("Stopping rescan for reorged block %v "+
"(replaced by block %v)", prevHash, curHash)
return &ErrRescanReorg
}
return nil
} | go | func descendantBlock(prevHash *chainhash.Hash, curBlock *btcutil.Block) error {
curHash := &curBlock.MsgBlock().Header.PrevBlock
if !prevHash.IsEqual(curHash) {
rpcsLog.Errorf("Stopping rescan for reorged block %v "+
"(replaced by block %v)", prevHash, curHash)
return &ErrRescanReorg
}
return nil
} | [
"func",
"descendantBlock",
"(",
"prevHash",
"*",
"chainhash",
".",
"Hash",
",",
"curBlock",
"*",
"btcutil",
".",
"Block",
")",
"error",
"{",
"curHash",
":=",
"&",
"curBlock",
".",
"MsgBlock",
"(",
")",
".",
"Header",
".",
"PrevBlock",
"\n",
"if",
"!",
... | // descendantBlock returns the appropriate JSON-RPC error if a current block
// fetched during a reorganize is not a direct child of the parent block hash. | [
"descendantBlock",
"returns",
"the",
"appropriate",
"JSON",
"-",
"RPC",
"error",
"if",
"a",
"current",
"block",
"fetched",
"during",
"a",
"reorganize",
"is",
"not",
"a",
"direct",
"child",
"of",
"the",
"parent",
"block",
"hash",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcwebsocket.go#L2314-L2322 |
163,608 | btcsuite/btcd | btcec/ciphering.go | Decrypt | func Decrypt(priv *PrivateKey, in []byte) ([]byte, error) {
// IV + Curve params/X/Y + 1 block + HMAC-256
if len(in) < aes.BlockSize+70+aes.BlockSize+sha256.Size {
return nil, errInputTooShort
}
// read iv
iv := in[:aes.BlockSize]
offset := aes.BlockSize
// start reading pubkey
if !bytes.Equal(in[offset:off... | go | func Decrypt(priv *PrivateKey, in []byte) ([]byte, error) {
// IV + Curve params/X/Y + 1 block + HMAC-256
if len(in) < aes.BlockSize+70+aes.BlockSize+sha256.Size {
return nil, errInputTooShort
}
// read iv
iv := in[:aes.BlockSize]
offset := aes.BlockSize
// start reading pubkey
if !bytes.Equal(in[offset:off... | [
"func",
"Decrypt",
"(",
"priv",
"*",
"PrivateKey",
",",
"in",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"// IV + Curve params/X/Y + 1 block + HMAC-256",
"if",
"len",
"(",
"in",
")",
"<",
"aes",
".",
"BlockSize",
"+",
"70",
"... | // Decrypt decrypts data that was encrypted using the Encrypt function. | [
"Decrypt",
"decrypts",
"data",
"that",
"was",
"encrypted",
"using",
"the",
"Encrypt",
"function",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/btcec/ciphering.go#L121-L196 |
163,609 | btcsuite/btcd | btcec/ciphering.go | removePKCSPadding | func removePKCSPadding(src []byte) ([]byte, error) {
length := len(src)
padLength := int(src[length-1])
if padLength > aes.BlockSize || length < aes.BlockSize {
return nil, errInvalidPadding
}
return src[:length-padLength], nil
} | go | func removePKCSPadding(src []byte) ([]byte, error) {
length := len(src)
padLength := int(src[length-1])
if padLength > aes.BlockSize || length < aes.BlockSize {
return nil, errInvalidPadding
}
return src[:length-padLength], nil
} | [
"func",
"removePKCSPadding",
"(",
"src",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"length",
":=",
"len",
"(",
"src",
")",
"\n",
"padLength",
":=",
"int",
"(",
"src",
"[",
"length",
"-",
"1",
"]",
")",
"\n",
"if",
"p... | // removePKCSPadding removes padding from data that was added with addPKCSPadding | [
"removePKCSPadding",
"removes",
"padding",
"from",
"data",
"that",
"was",
"added",
"with",
"addPKCSPadding"
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/btcec/ciphering.go#L208-L216 |
163,610 | btcsuite/btcd | database/internal/treap/common.go | nodeSize | func nodeSize(node *treapNode) uint64 {
return nodeFieldsSize + uint64(len(node.key)+len(node.value))
} | go | func nodeSize(node *treapNode) uint64 {
return nodeFieldsSize + uint64(len(node.key)+len(node.value))
} | [
"func",
"nodeSize",
"(",
"node",
"*",
"treapNode",
")",
"uint64",
"{",
"return",
"nodeFieldsSize",
"+",
"uint64",
"(",
"len",
"(",
"node",
".",
"key",
")",
"+",
"len",
"(",
"node",
".",
"value",
")",
")",
"\n",
"}"
] | // nodeSize returns the number of bytes the specified node occupies including
// the struct fields and the contents of the key and value. | [
"nodeSize",
"returns",
"the",
"number",
"of",
"bytes",
"the",
"specified",
"node",
"occupies",
"including",
"the",
"struct",
"fields",
"and",
"the",
"contents",
"of",
"the",
"key",
"and",
"value",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/database/internal/treap/common.go#L47-L49 |
163,611 | btcsuite/btcd | database/internal/treap/common.go | newTreapNode | func newTreapNode(key, value []byte, priority int) *treapNode {
return &treapNode{key: key, value: value, priority: priority}
} | go | func newTreapNode(key, value []byte, priority int) *treapNode {
return &treapNode{key: key, value: value, priority: priority}
} | [
"func",
"newTreapNode",
"(",
"key",
",",
"value",
"[",
"]",
"byte",
",",
"priority",
"int",
")",
"*",
"treapNode",
"{",
"return",
"&",
"treapNode",
"{",
"key",
":",
"key",
",",
"value",
":",
"value",
",",
"priority",
":",
"priority",
"}",
"\n",
"}"
] | // newTreapNode returns a new node from the given key, value, and priority. The
// node is not initially linked to any others. | [
"newTreapNode",
"returns",
"a",
"new",
"node",
"from",
"the",
"given",
"key",
"value",
"and",
"priority",
".",
"The",
"node",
"is",
"not",
"initially",
"linked",
"to",
"any",
"others",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/database/internal/treap/common.go#L53-L55 |
163,612 | btcsuite/btcd | database/internal/treap/common.go | At | func (s *parentStack) At(n int) *treapNode {
index := s.index - n - 1
if index < 0 {
return nil
}
if index < staticDepth {
return s.items[index]
}
return s.overflow[index-staticDepth]
} | go | func (s *parentStack) At(n int) *treapNode {
index := s.index - n - 1
if index < 0 {
return nil
}
if index < staticDepth {
return s.items[index]
}
return s.overflow[index-staticDepth]
} | [
"func",
"(",
"s",
"*",
"parentStack",
")",
"At",
"(",
"n",
"int",
")",
"*",
"treapNode",
"{",
"index",
":=",
"s",
".",
"index",
"-",
"n",
"-",
"1",
"\n",
"if",
"index",
"<",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"index",
"<",
"s... | // At returns the item n number of items from the top of the stack, where 0 is
// the topmost item, without removing it. It returns nil if n exceeds the
// number of items on the stack. | [
"At",
"returns",
"the",
"item",
"n",
"number",
"of",
"items",
"from",
"the",
"top",
"of",
"the",
"stack",
"where",
"0",
"is",
"the",
"topmost",
"item",
"without",
"removing",
"it",
".",
"It",
"returns",
"nil",
"if",
"n",
"exceeds",
"the",
"number",
"of... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/database/internal/treap/common.go#L78-L89 |
163,613 | btcsuite/btcd | database/internal/treap/common.go | Pop | func (s *parentStack) Pop() *treapNode {
if s.index == 0 {
return nil
}
s.index--
if s.index < staticDepth {
node := s.items[s.index]
s.items[s.index] = nil
return node
}
node := s.overflow[s.index-staticDepth]
s.overflow[s.index-staticDepth] = nil
return node
} | go | func (s *parentStack) Pop() *treapNode {
if s.index == 0 {
return nil
}
s.index--
if s.index < staticDepth {
node := s.items[s.index]
s.items[s.index] = nil
return node
}
node := s.overflow[s.index-staticDepth]
s.overflow[s.index-staticDepth] = nil
return node
} | [
"func",
"(",
"s",
"*",
"parentStack",
")",
"Pop",
"(",
")",
"*",
"treapNode",
"{",
"if",
"s",
".",
"index",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"s",
".",
"index",
"--",
"\n",
"if",
"s",
".",
"index",
"<",
"staticDepth",
"{",
"no... | // Pop removes the top item from the stack. It returns nil if the stack is
// empty. | [
"Pop",
"removes",
"the",
"top",
"item",
"from",
"the",
"stack",
".",
"It",
"returns",
"nil",
"if",
"the",
"stack",
"is",
"empty",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/database/internal/treap/common.go#L93-L108 |
163,614 | btcsuite/btcd | database/internal/treap/common.go | Push | func (s *parentStack) Push(node *treapNode) {
if s.index < staticDepth {
s.items[s.index] = node
s.index++
return
}
// This approach is used over append because reslicing the slice to pop
// the item causes the compiler to make unneeded allocations. Also,
// since the max number of items is related to the ... | go | func (s *parentStack) Push(node *treapNode) {
if s.index < staticDepth {
s.items[s.index] = node
s.index++
return
}
// This approach is used over append because reslicing the slice to pop
// the item causes the compiler to make unneeded allocations. Also,
// since the max number of items is related to the ... | [
"func",
"(",
"s",
"*",
"parentStack",
")",
"Push",
"(",
"node",
"*",
"treapNode",
")",
"{",
"if",
"s",
".",
"index",
"<",
"staticDepth",
"{",
"s",
".",
"items",
"[",
"s",
".",
"index",
"]",
"=",
"node",
"\n",
"s",
".",
"index",
"++",
"\n",
"ret... | // Push pushes the passed item onto the top of the stack. | [
"Push",
"pushes",
"the",
"passed",
"item",
"onto",
"the",
"top",
"of",
"the",
"stack",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/database/internal/treap/common.go#L111-L132 |
163,615 | btcsuite/btcd | peer/peer.go | newNetAddress | func newNetAddress(addr net.Addr, services wire.ServiceFlag) (*wire.NetAddress, error) {
// addr will be a net.TCPAddr when not using a proxy.
if tcpAddr, ok := addr.(*net.TCPAddr); ok {
ip := tcpAddr.IP
port := uint16(tcpAddr.Port)
na := wire.NewNetAddressIPPort(ip, port, services)
return na, nil
}
// add... | go | func newNetAddress(addr net.Addr, services wire.ServiceFlag) (*wire.NetAddress, error) {
// addr will be a net.TCPAddr when not using a proxy.
if tcpAddr, ok := addr.(*net.TCPAddr); ok {
ip := tcpAddr.IP
port := uint16(tcpAddr.Port)
na := wire.NewNetAddressIPPort(ip, port, services)
return na, nil
}
// add... | [
"func",
"newNetAddress",
"(",
"addr",
"net",
".",
"Addr",
",",
"services",
"wire",
".",
"ServiceFlag",
")",
"(",
"*",
"wire",
".",
"NetAddress",
",",
"error",
")",
"{",
"// addr will be a net.TCPAddr when not using a proxy.",
"if",
"tcpAddr",
",",
"ok",
":=",
... | // newNetAddress attempts to extract the IP address and port from the passed
// net.Addr interface and create a bitcoin NetAddress structure using that
// information. | [
"newNetAddress",
"attempts",
"to",
"extract",
"the",
"IP",
"address",
"and",
"port",
"from",
"the",
"passed",
"net",
".",
"Addr",
"interface",
"and",
"create",
"a",
"bitcoin",
"NetAddress",
"structure",
"using",
"that",
"information",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L292-L326 |
163,616 | btcsuite/btcd | peer/peer.go | String | func (p *Peer) String() string {
return fmt.Sprintf("%s (%s)", p.addr, directionString(p.inbound))
} | go | func (p *Peer) String() string {
return fmt.Sprintf("%s (%s)", p.addr, directionString(p.inbound))
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"p",
".",
"addr",
",",
"directionString",
"(",
"p",
".",
"inbound",
")",
")",
"\n",
"}"
] | // String returns the peer's address and directionality as a human-readable
// string.
//
// This function is safe for concurrent access. | [
"String",
"returns",
"the",
"peer",
"s",
"address",
"and",
"directionality",
"as",
"a",
"human",
"-",
"readable",
"string",
".",
"This",
"function",
"is",
"safe",
"for",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L488-L490 |
163,617 | btcsuite/btcd | peer/peer.go | UpdateLastBlockHeight | func (p *Peer) UpdateLastBlockHeight(newHeight int32) {
p.statsMtx.Lock()
log.Tracef("Updating last block height of peer %v from %v to %v",
p.addr, p.lastBlock, newHeight)
p.lastBlock = newHeight
p.statsMtx.Unlock()
} | go | func (p *Peer) UpdateLastBlockHeight(newHeight int32) {
p.statsMtx.Lock()
log.Tracef("Updating last block height of peer %v from %v to %v",
p.addr, p.lastBlock, newHeight)
p.lastBlock = newHeight
p.statsMtx.Unlock()
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"UpdateLastBlockHeight",
"(",
"newHeight",
"int32",
")",
"{",
"p",
".",
"statsMtx",
".",
"Lock",
"(",
")",
"\n",
"log",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"p",
".",
"addr",
",",
"p",
".",
"lastBlock",
",",
"n... | // UpdateLastBlockHeight updates the last known block for the peer.
//
// This function is safe for concurrent access. | [
"UpdateLastBlockHeight",
"updates",
"the",
"last",
"known",
"block",
"for",
"the",
"peer",
".",
"This",
"function",
"is",
"safe",
"for",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L495-L501 |
163,618 | btcsuite/btcd | peer/peer.go | UpdateLastAnnouncedBlock | func (p *Peer) UpdateLastAnnouncedBlock(blkHash *chainhash.Hash) {
log.Tracef("Updating last blk for peer %v, %v", p.addr, blkHash)
p.statsMtx.Lock()
p.lastAnnouncedBlock = blkHash
p.statsMtx.Unlock()
} | go | func (p *Peer) UpdateLastAnnouncedBlock(blkHash *chainhash.Hash) {
log.Tracef("Updating last blk for peer %v, %v", p.addr, blkHash)
p.statsMtx.Lock()
p.lastAnnouncedBlock = blkHash
p.statsMtx.Unlock()
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"UpdateLastAnnouncedBlock",
"(",
"blkHash",
"*",
"chainhash",
".",
"Hash",
")",
"{",
"log",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"p",
".",
"addr",
",",
"blkHash",
")",
"\n\n",
"p",
".",
"statsMtx",
".",
"Lock",
"... | // UpdateLastAnnouncedBlock updates meta-data about the last block hash this
// peer is known to have announced.
//
// This function is safe for concurrent access. | [
"UpdateLastAnnouncedBlock",
"updates",
"meta",
"-",
"data",
"about",
"the",
"last",
"block",
"hash",
"this",
"peer",
"is",
"known",
"to",
"have",
"announced",
".",
"This",
"function",
"is",
"safe",
"for",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L507-L513 |
163,619 | btcsuite/btcd | peer/peer.go | AddKnownInventory | func (p *Peer) AddKnownInventory(invVect *wire.InvVect) {
p.knownInventory.Add(invVect)
} | go | func (p *Peer) AddKnownInventory(invVect *wire.InvVect) {
p.knownInventory.Add(invVect)
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"AddKnownInventory",
"(",
"invVect",
"*",
"wire",
".",
"InvVect",
")",
"{",
"p",
".",
"knownInventory",
".",
"Add",
"(",
"invVect",
")",
"\n",
"}"
] | // AddKnownInventory adds the passed inventory to the cache of known inventory
// for the peer.
//
// This function is safe for concurrent access. | [
"AddKnownInventory",
"adds",
"the",
"passed",
"inventory",
"to",
"the",
"cache",
"of",
"known",
"inventory",
"for",
"the",
"peer",
".",
"This",
"function",
"is",
"safe",
"for",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L519-L521 |
163,620 | btcsuite/btcd | peer/peer.go | StatsSnapshot | func (p *Peer) StatsSnapshot() *StatsSnap {
p.statsMtx.RLock()
p.flagsMtx.Lock()
id := p.id
addr := p.addr
userAgent := p.userAgent
services := p.services
protocolVersion := p.advertisedProtoVer
p.flagsMtx.Unlock()
// Get a copy of all relevant flags and stats.
statsSnap := &StatsSnap{
ID: id,... | go | func (p *Peer) StatsSnapshot() *StatsSnap {
p.statsMtx.RLock()
p.flagsMtx.Lock()
id := p.id
addr := p.addr
userAgent := p.userAgent
services := p.services
protocolVersion := p.advertisedProtoVer
p.flagsMtx.Unlock()
// Get a copy of all relevant flags and stats.
statsSnap := &StatsSnap{
ID: id,... | [
"func",
"(",
"p",
"*",
"Peer",
")",
"StatsSnapshot",
"(",
")",
"*",
"StatsSnap",
"{",
"p",
".",
"statsMtx",
".",
"RLock",
"(",
")",
"\n\n",
"p",
".",
"flagsMtx",
".",
"Lock",
"(",
")",
"\n",
"id",
":=",
"p",
".",
"id",
"\n",
"addr",
":=",
"p",
... | // StatsSnapshot returns a snapshot of the current peer flags and statistics.
//
// This function is safe for concurrent access. | [
"StatsSnapshot",
"returns",
"a",
"snapshot",
"of",
"the",
"current",
"peer",
"flags",
"and",
"statistics",
".",
"This",
"function",
"is",
"safe",
"for",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L526-L560 |
163,621 | btcsuite/btcd | peer/peer.go | ID | func (p *Peer) ID() int32 {
p.flagsMtx.Lock()
id := p.id
p.flagsMtx.Unlock()
return id
} | go | func (p *Peer) ID() int32 {
p.flagsMtx.Lock()
id := p.id
p.flagsMtx.Unlock()
return id
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"ID",
"(",
")",
"int32",
"{",
"p",
".",
"flagsMtx",
".",
"Lock",
"(",
")",
"\n",
"id",
":=",
"p",
".",
"id",
"\n",
"p",
".",
"flagsMtx",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"id",
"\n",
"}"
] | // ID returns the peer id.
//
// This function is safe for concurrent access. | [
"ID",
"returns",
"the",
"peer",
"id",
".",
"This",
"function",
"is",
"safe",
"for",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L565-L571 |
163,622 | btcsuite/btcd | peer/peer.go | NA | func (p *Peer) NA() *wire.NetAddress {
p.flagsMtx.Lock()
na := p.na
p.flagsMtx.Unlock()
return na
} | go | func (p *Peer) NA() *wire.NetAddress {
p.flagsMtx.Lock()
na := p.na
p.flagsMtx.Unlock()
return na
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"NA",
"(",
")",
"*",
"wire",
".",
"NetAddress",
"{",
"p",
".",
"flagsMtx",
".",
"Lock",
"(",
")",
"\n",
"na",
":=",
"p",
".",
"na",
"\n",
"p",
".",
"flagsMtx",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"na... | // NA returns the peer network address.
//
// This function is safe for concurrent access. | [
"NA",
"returns",
"the",
"peer",
"network",
"address",
".",
"This",
"function",
"is",
"safe",
"for",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L576-L582 |
163,623 | btcsuite/btcd | peer/peer.go | Services | func (p *Peer) Services() wire.ServiceFlag {
p.flagsMtx.Lock()
services := p.services
p.flagsMtx.Unlock()
return services
} | go | func (p *Peer) Services() wire.ServiceFlag {
p.flagsMtx.Lock()
services := p.services
p.flagsMtx.Unlock()
return services
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"Services",
"(",
")",
"wire",
".",
"ServiceFlag",
"{",
"p",
".",
"flagsMtx",
".",
"Lock",
"(",
")",
"\n",
"services",
":=",
"p",
".",
"services",
"\n",
"p",
".",
"flagsMtx",
".",
"Unlock",
"(",
")",
"\n\n",
"re... | // Services returns the services flag of the remote peer.
//
// This function is safe for concurrent access. | [
"Services",
"returns",
"the",
"services",
"flag",
"of",
"the",
"remote",
"peer",
".",
"This",
"function",
"is",
"safe",
"for",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L603-L609 |
163,624 | btcsuite/btcd | peer/peer.go | UserAgent | func (p *Peer) UserAgent() string {
p.flagsMtx.Lock()
userAgent := p.userAgent
p.flagsMtx.Unlock()
return userAgent
} | go | func (p *Peer) UserAgent() string {
p.flagsMtx.Lock()
userAgent := p.userAgent
p.flagsMtx.Unlock()
return userAgent
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"UserAgent",
"(",
")",
"string",
"{",
"p",
".",
"flagsMtx",
".",
"Lock",
"(",
")",
"\n",
"userAgent",
":=",
"p",
".",
"userAgent",
"\n",
"p",
".",
"flagsMtx",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"userAgent... | // UserAgent returns the user agent of the remote peer.
//
// This function is safe for concurrent access. | [
"UserAgent",
"returns",
"the",
"user",
"agent",
"of",
"the",
"remote",
"peer",
".",
"This",
"function",
"is",
"safe",
"for",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L614-L620 |
163,625 | btcsuite/btcd | peer/peer.go | LastAnnouncedBlock | func (p *Peer) LastAnnouncedBlock() *chainhash.Hash {
p.statsMtx.RLock()
lastAnnouncedBlock := p.lastAnnouncedBlock
p.statsMtx.RUnlock()
return lastAnnouncedBlock
} | go | func (p *Peer) LastAnnouncedBlock() *chainhash.Hash {
p.statsMtx.RLock()
lastAnnouncedBlock := p.lastAnnouncedBlock
p.statsMtx.RUnlock()
return lastAnnouncedBlock
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"LastAnnouncedBlock",
"(",
")",
"*",
"chainhash",
".",
"Hash",
"{",
"p",
".",
"statsMtx",
".",
"RLock",
"(",
")",
"\n",
"lastAnnouncedBlock",
":=",
"p",
".",
"lastAnnouncedBlock",
"\n",
"p",
".",
"statsMtx",
".",
"RU... | // LastAnnouncedBlock returns the last announced block of the remote peer.
//
// This function is safe for concurrent access. | [
"LastAnnouncedBlock",
"returns",
"the",
"last",
"announced",
"block",
"of",
"the",
"remote",
"peer",
".",
"This",
"function",
"is",
"safe",
"for",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L625-L631 |
163,626 | btcsuite/btcd | peer/peer.go | LastPingNonce | func (p *Peer) LastPingNonce() uint64 {
p.statsMtx.RLock()
lastPingNonce := p.lastPingNonce
p.statsMtx.RUnlock()
return lastPingNonce
} | go | func (p *Peer) LastPingNonce() uint64 {
p.statsMtx.RLock()
lastPingNonce := p.lastPingNonce
p.statsMtx.RUnlock()
return lastPingNonce
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"LastPingNonce",
"(",
")",
"uint64",
"{",
"p",
".",
"statsMtx",
".",
"RLock",
"(",
")",
"\n",
"lastPingNonce",
":=",
"p",
".",
"lastPingNonce",
"\n",
"p",
".",
"statsMtx",
".",
"RUnlock",
"(",
")",
"\n\n",
"return"... | // LastPingNonce returns the last ping nonce of the remote peer.
//
// This function is safe for concurrent access. | [
"LastPingNonce",
"returns",
"the",
"last",
"ping",
"nonce",
"of",
"the",
"remote",
"peer",
".",
"This",
"function",
"is",
"safe",
"for",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L636-L642 |
163,627 | btcsuite/btcd | peer/peer.go | LastPingTime | func (p *Peer) LastPingTime() time.Time {
p.statsMtx.RLock()
lastPingTime := p.lastPingTime
p.statsMtx.RUnlock()
return lastPingTime
} | go | func (p *Peer) LastPingTime() time.Time {
p.statsMtx.RLock()
lastPingTime := p.lastPingTime
p.statsMtx.RUnlock()
return lastPingTime
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"LastPingTime",
"(",
")",
"time",
".",
"Time",
"{",
"p",
".",
"statsMtx",
".",
"RLock",
"(",
")",
"\n",
"lastPingTime",
":=",
"p",
".",
"lastPingTime",
"\n",
"p",
".",
"statsMtx",
".",
"RUnlock",
"(",
")",
"\n\n"... | // LastPingTime returns the last ping time of the remote peer.
//
// This function is safe for concurrent access. | [
"LastPingTime",
"returns",
"the",
"last",
"ping",
"time",
"of",
"the",
"remote",
"peer",
".",
"This",
"function",
"is",
"safe",
"for",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L647-L653 |
163,628 | btcsuite/btcd | peer/peer.go | LastPingMicros | func (p *Peer) LastPingMicros() int64 {
p.statsMtx.RLock()
lastPingMicros := p.lastPingMicros
p.statsMtx.RUnlock()
return lastPingMicros
} | go | func (p *Peer) LastPingMicros() int64 {
p.statsMtx.RLock()
lastPingMicros := p.lastPingMicros
p.statsMtx.RUnlock()
return lastPingMicros
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"LastPingMicros",
"(",
")",
"int64",
"{",
"p",
".",
"statsMtx",
".",
"RLock",
"(",
")",
"\n",
"lastPingMicros",
":=",
"p",
".",
"lastPingMicros",
"\n",
"p",
".",
"statsMtx",
".",
"RUnlock",
"(",
")",
"\n\n",
"retur... | // LastPingMicros returns the last ping micros of the remote peer.
//
// This function is safe for concurrent access. | [
"LastPingMicros",
"returns",
"the",
"last",
"ping",
"micros",
"of",
"the",
"remote",
"peer",
".",
"This",
"function",
"is",
"safe",
"for",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L658-L664 |
163,629 | btcsuite/btcd | peer/peer.go | VersionKnown | func (p *Peer) VersionKnown() bool {
p.flagsMtx.Lock()
versionKnown := p.versionKnown
p.flagsMtx.Unlock()
return versionKnown
} | go | func (p *Peer) VersionKnown() bool {
p.flagsMtx.Lock()
versionKnown := p.versionKnown
p.flagsMtx.Unlock()
return versionKnown
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"VersionKnown",
"(",
")",
"bool",
"{",
"p",
".",
"flagsMtx",
".",
"Lock",
"(",
")",
"\n",
"versionKnown",
":=",
"p",
".",
"versionKnown",
"\n",
"p",
".",
"flagsMtx",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"ve... | // VersionKnown returns the whether or not the version of a peer is known
// locally.
//
// This function is safe for concurrent access. | [
"VersionKnown",
"returns",
"the",
"whether",
"or",
"not",
"the",
"version",
"of",
"a",
"peer",
"is",
"known",
"locally",
".",
"This",
"function",
"is",
"safe",
"for",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L670-L676 |
163,630 | btcsuite/btcd | peer/peer.go | VerAckReceived | func (p *Peer) VerAckReceived() bool {
p.flagsMtx.Lock()
verAckReceived := p.verAckReceived
p.flagsMtx.Unlock()
return verAckReceived
} | go | func (p *Peer) VerAckReceived() bool {
p.flagsMtx.Lock()
verAckReceived := p.verAckReceived
p.flagsMtx.Unlock()
return verAckReceived
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"VerAckReceived",
"(",
")",
"bool",
"{",
"p",
".",
"flagsMtx",
".",
"Lock",
"(",
")",
"\n",
"verAckReceived",
":=",
"p",
".",
"verAckReceived",
"\n",
"p",
".",
"flagsMtx",
".",
"Unlock",
"(",
")",
"\n\n",
"return",... | // VerAckReceived returns whether or not a verack message was received by the
// peer.
//
// This function is safe for concurrent access. | [
"VerAckReceived",
"returns",
"whether",
"or",
"not",
"a",
"verack",
"message",
"was",
"received",
"by",
"the",
"peer",
".",
"This",
"function",
"is",
"safe",
"for",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L682-L688 |
163,631 | btcsuite/btcd | peer/peer.go | ProtocolVersion | func (p *Peer) ProtocolVersion() uint32 {
p.flagsMtx.Lock()
protocolVersion := p.protocolVersion
p.flagsMtx.Unlock()
return protocolVersion
} | go | func (p *Peer) ProtocolVersion() uint32 {
p.flagsMtx.Lock()
protocolVersion := p.protocolVersion
p.flagsMtx.Unlock()
return protocolVersion
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"ProtocolVersion",
"(",
")",
"uint32",
"{",
"p",
".",
"flagsMtx",
".",
"Lock",
"(",
")",
"\n",
"protocolVersion",
":=",
"p",
".",
"protocolVersion",
"\n",
"p",
".",
"flagsMtx",
".",
"Unlock",
"(",
")",
"\n\n",
"ret... | // ProtocolVersion returns the negotiated peer protocol version.
//
// This function is safe for concurrent access. | [
"ProtocolVersion",
"returns",
"the",
"negotiated",
"peer",
"protocol",
"version",
".",
"This",
"function",
"is",
"safe",
"for",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L693-L699 |
163,632 | btcsuite/btcd | peer/peer.go | LastBlock | func (p *Peer) LastBlock() int32 {
p.statsMtx.RLock()
lastBlock := p.lastBlock
p.statsMtx.RUnlock()
return lastBlock
} | go | func (p *Peer) LastBlock() int32 {
p.statsMtx.RLock()
lastBlock := p.lastBlock
p.statsMtx.RUnlock()
return lastBlock
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"LastBlock",
"(",
")",
"int32",
"{",
"p",
".",
"statsMtx",
".",
"RLock",
"(",
")",
"\n",
"lastBlock",
":=",
"p",
".",
"lastBlock",
"\n",
"p",
".",
"statsMtx",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"lastBloc... | // LastBlock returns the last block of the peer.
//
// This function is safe for concurrent access. | [
"LastBlock",
"returns",
"the",
"last",
"block",
"of",
"the",
"peer",
".",
"This",
"function",
"is",
"safe",
"for",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L704-L710 |
163,633 | btcsuite/btcd | peer/peer.go | LastSend | func (p *Peer) LastSend() time.Time {
return time.Unix(atomic.LoadInt64(&p.lastSend), 0)
} | go | func (p *Peer) LastSend() time.Time {
return time.Unix(atomic.LoadInt64(&p.lastSend), 0)
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"LastSend",
"(",
")",
"time",
".",
"Time",
"{",
"return",
"time",
".",
"Unix",
"(",
"atomic",
".",
"LoadInt64",
"(",
"&",
"p",
".",
"lastSend",
")",
",",
"0",
")",
"\n",
"}"
] | // LastSend returns the last send time of the peer.
//
// This function is safe for concurrent access. | [
"LastSend",
"returns",
"the",
"last",
"send",
"time",
"of",
"the",
"peer",
".",
"This",
"function",
"is",
"safe",
"for",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L715-L717 |
163,634 | btcsuite/btcd | peer/peer.go | LastRecv | func (p *Peer) LastRecv() time.Time {
return time.Unix(atomic.LoadInt64(&p.lastRecv), 0)
} | go | func (p *Peer) LastRecv() time.Time {
return time.Unix(atomic.LoadInt64(&p.lastRecv), 0)
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"LastRecv",
"(",
")",
"time",
".",
"Time",
"{",
"return",
"time",
".",
"Unix",
"(",
"atomic",
".",
"LoadInt64",
"(",
"&",
"p",
".",
"lastRecv",
")",
",",
"0",
")",
"\n",
"}"
] | // LastRecv returns the last recv time of the peer.
//
// This function is safe for concurrent access. | [
"LastRecv",
"returns",
"the",
"last",
"recv",
"time",
"of",
"the",
"peer",
".",
"This",
"function",
"is",
"safe",
"for",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L722-L724 |
163,635 | btcsuite/btcd | peer/peer.go | LocalAddr | func (p *Peer) LocalAddr() net.Addr {
var localAddr net.Addr
if atomic.LoadInt32(&p.connected) != 0 {
localAddr = p.conn.LocalAddr()
}
return localAddr
} | go | func (p *Peer) LocalAddr() net.Addr {
var localAddr net.Addr
if atomic.LoadInt32(&p.connected) != 0 {
localAddr = p.conn.LocalAddr()
}
return localAddr
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"LocalAddr",
"(",
")",
"net",
".",
"Addr",
"{",
"var",
"localAddr",
"net",
".",
"Addr",
"\n",
"if",
"atomic",
".",
"LoadInt32",
"(",
"&",
"p",
".",
"connected",
")",
"!=",
"0",
"{",
"localAddr",
"=",
"p",
".",
... | // LocalAddr returns the local address of the connection.
//
// This function is safe fo concurrent access. | [
"LocalAddr",
"returns",
"the",
"local",
"address",
"of",
"the",
"connection",
".",
"This",
"function",
"is",
"safe",
"fo",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L729-L735 |
163,636 | btcsuite/btcd | peer/peer.go | TimeConnected | func (p *Peer) TimeConnected() time.Time {
p.statsMtx.RLock()
timeConnected := p.timeConnected
p.statsMtx.RUnlock()
return timeConnected
} | go | func (p *Peer) TimeConnected() time.Time {
p.statsMtx.RLock()
timeConnected := p.timeConnected
p.statsMtx.RUnlock()
return timeConnected
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"TimeConnected",
"(",
")",
"time",
".",
"Time",
"{",
"p",
".",
"statsMtx",
".",
"RLock",
"(",
")",
"\n",
"timeConnected",
":=",
"p",
".",
"timeConnected",
"\n",
"p",
".",
"statsMtx",
".",
"RUnlock",
"(",
")",
"\n... | // TimeConnected returns the time at which the peer connected.
//
// This function is safe for concurrent access. | [
"TimeConnected",
"returns",
"the",
"time",
"at",
"which",
"the",
"peer",
"connected",
".",
"This",
"function",
"is",
"safe",
"for",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L754-L760 |
163,637 | btcsuite/btcd | peer/peer.go | TimeOffset | func (p *Peer) TimeOffset() int64 {
p.statsMtx.RLock()
timeOffset := p.timeOffset
p.statsMtx.RUnlock()
return timeOffset
} | go | func (p *Peer) TimeOffset() int64 {
p.statsMtx.RLock()
timeOffset := p.timeOffset
p.statsMtx.RUnlock()
return timeOffset
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"TimeOffset",
"(",
")",
"int64",
"{",
"p",
".",
"statsMtx",
".",
"RLock",
"(",
")",
"\n",
"timeOffset",
":=",
"p",
".",
"timeOffset",
"\n",
"p",
".",
"statsMtx",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"timeO... | // TimeOffset returns the number of seconds the local time was offset from the
// time the peer reported during the initial negotiation phase. Negative values
// indicate the remote peer's time is before the local time.
//
// This function is safe for concurrent access. | [
"TimeOffset",
"returns",
"the",
"number",
"of",
"seconds",
"the",
"local",
"time",
"was",
"offset",
"from",
"the",
"time",
"the",
"peer",
"reported",
"during",
"the",
"initial",
"negotiation",
"phase",
".",
"Negative",
"values",
"indicate",
"the",
"remote",
"p... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L767-L773 |
163,638 | btcsuite/btcd | peer/peer.go | StartingHeight | func (p *Peer) StartingHeight() int32 {
p.statsMtx.RLock()
startingHeight := p.startingHeight
p.statsMtx.RUnlock()
return startingHeight
} | go | func (p *Peer) StartingHeight() int32 {
p.statsMtx.RLock()
startingHeight := p.startingHeight
p.statsMtx.RUnlock()
return startingHeight
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"StartingHeight",
"(",
")",
"int32",
"{",
"p",
".",
"statsMtx",
".",
"RLock",
"(",
")",
"\n",
"startingHeight",
":=",
"p",
".",
"startingHeight",
"\n",
"p",
".",
"statsMtx",
".",
"RUnlock",
"(",
")",
"\n\n",
"retur... | // StartingHeight returns the last known height the peer reported during the
// initial negotiation phase.
//
// This function is safe for concurrent access. | [
"StartingHeight",
"returns",
"the",
"last",
"known",
"height",
"the",
"peer",
"reported",
"during",
"the",
"initial",
"negotiation",
"phase",
".",
"This",
"function",
"is",
"safe",
"for",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L779-L785 |
163,639 | btcsuite/btcd | peer/peer.go | WantsHeaders | func (p *Peer) WantsHeaders() bool {
p.flagsMtx.Lock()
sendHeadersPreferred := p.sendHeadersPreferred
p.flagsMtx.Unlock()
return sendHeadersPreferred
} | go | func (p *Peer) WantsHeaders() bool {
p.flagsMtx.Lock()
sendHeadersPreferred := p.sendHeadersPreferred
p.flagsMtx.Unlock()
return sendHeadersPreferred
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"WantsHeaders",
"(",
")",
"bool",
"{",
"p",
".",
"flagsMtx",
".",
"Lock",
"(",
")",
"\n",
"sendHeadersPreferred",
":=",
"p",
".",
"sendHeadersPreferred",
"\n",
"p",
".",
"flagsMtx",
".",
"Unlock",
"(",
")",
"\n\n",
... | // WantsHeaders returns if the peer wants header messages instead of
// inventory vectors for blocks.
//
// This function is safe for concurrent access. | [
"WantsHeaders",
"returns",
"if",
"the",
"peer",
"wants",
"header",
"messages",
"instead",
"of",
"inventory",
"vectors",
"for",
"blocks",
".",
"This",
"function",
"is",
"safe",
"for",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L791-L797 |
163,640 | btcsuite/btcd | peer/peer.go | IsWitnessEnabled | func (p *Peer) IsWitnessEnabled() bool {
p.flagsMtx.Lock()
witnessEnabled := p.witnessEnabled
p.flagsMtx.Unlock()
return witnessEnabled
} | go | func (p *Peer) IsWitnessEnabled() bool {
p.flagsMtx.Lock()
witnessEnabled := p.witnessEnabled
p.flagsMtx.Unlock()
return witnessEnabled
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"IsWitnessEnabled",
"(",
")",
"bool",
"{",
"p",
".",
"flagsMtx",
".",
"Lock",
"(",
")",
"\n",
"witnessEnabled",
":=",
"p",
".",
"witnessEnabled",
"\n",
"p",
".",
"flagsMtx",
".",
"Unlock",
"(",
")",
"\n\n",
"return... | // IsWitnessEnabled returns true if the peer has signalled that it supports
// segregated witness.
//
// This function is safe for concurrent access. | [
"IsWitnessEnabled",
"returns",
"true",
"if",
"the",
"peer",
"has",
"signalled",
"that",
"it",
"supports",
"segregated",
"witness",
".",
"This",
"function",
"is",
"safe",
"for",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L803-L809 |
163,641 | btcsuite/btcd | peer/peer.go | PushAddrMsg | func (p *Peer) PushAddrMsg(addresses []*wire.NetAddress) ([]*wire.NetAddress, error) {
addressCount := len(addresses)
// Nothing to send.
if addressCount == 0 {
return nil, nil
}
msg := wire.NewMsgAddr()
msg.AddrList = make([]*wire.NetAddress, addressCount)
copy(msg.AddrList, addresses)
// Randomize the ad... | go | func (p *Peer) PushAddrMsg(addresses []*wire.NetAddress) ([]*wire.NetAddress, error) {
addressCount := len(addresses)
// Nothing to send.
if addressCount == 0 {
return nil, nil
}
msg := wire.NewMsgAddr()
msg.AddrList = make([]*wire.NetAddress, addressCount)
copy(msg.AddrList, addresses)
// Randomize the ad... | [
"func",
"(",
"p",
"*",
"Peer",
")",
"PushAddrMsg",
"(",
"addresses",
"[",
"]",
"*",
"wire",
".",
"NetAddress",
")",
"(",
"[",
"]",
"*",
"wire",
".",
"NetAddress",
",",
"error",
")",
"{",
"addressCount",
":=",
"len",
"(",
"addresses",
")",
"\n\n",
"... | // PushAddrMsg sends an addr message to the connected peer using the provided
// addresses. This function is useful over manually sending the message via
// QueueMessage since it automatically limits the addresses to the maximum
// number allowed by the message and randomizes the chosen addresses when there
// are too... | [
"PushAddrMsg",
"sends",
"an",
"addr",
"message",
"to",
"the",
"connected",
"peer",
"using",
"the",
"provided",
"addresses",
".",
"This",
"function",
"is",
"useful",
"over",
"manually",
"sending",
"the",
"message",
"via",
"QueueMessage",
"since",
"it",
"automatic... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L819-L845 |
163,642 | btcsuite/btcd | peer/peer.go | PushGetBlocksMsg | func (p *Peer) PushGetBlocksMsg(locator blockchain.BlockLocator, stopHash *chainhash.Hash) error {
// Extract the begin hash from the block locator, if one was specified,
// to use for filtering duplicate getblocks requests.
var beginHash *chainhash.Hash
if len(locator) > 0 {
beginHash = locator[0]
}
// Filter... | go | func (p *Peer) PushGetBlocksMsg(locator blockchain.BlockLocator, stopHash *chainhash.Hash) error {
// Extract the begin hash from the block locator, if one was specified,
// to use for filtering duplicate getblocks requests.
var beginHash *chainhash.Hash
if len(locator) > 0 {
beginHash = locator[0]
}
// Filter... | [
"func",
"(",
"p",
"*",
"Peer",
")",
"PushGetBlocksMsg",
"(",
"locator",
"blockchain",
".",
"BlockLocator",
",",
"stopHash",
"*",
"chainhash",
".",
"Hash",
")",
"error",
"{",
"// Extract the begin hash from the block locator, if one was specified,",
"// to use for filterin... | // PushGetBlocksMsg sends a getblocks message for the provided block locator
// and stop hash. It will ignore back-to-back duplicate requests.
//
// This function is safe for concurrent access. | [
"PushGetBlocksMsg",
"sends",
"a",
"getblocks",
"message",
"for",
"the",
"provided",
"block",
"locator",
"and",
"stop",
"hash",
".",
"It",
"will",
"ignore",
"back",
"-",
"to",
"-",
"back",
"duplicate",
"requests",
".",
"This",
"function",
"is",
"safe",
"for",... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L851-L889 |
163,643 | btcsuite/btcd | peer/peer.go | PushGetHeadersMsg | func (p *Peer) PushGetHeadersMsg(locator blockchain.BlockLocator, stopHash *chainhash.Hash) error {
// Extract the begin hash from the block locator, if one was specified,
// to use for filtering duplicate getheaders requests.
var beginHash *chainhash.Hash
if len(locator) > 0 {
beginHash = locator[0]
}
// Filt... | go | func (p *Peer) PushGetHeadersMsg(locator blockchain.BlockLocator, stopHash *chainhash.Hash) error {
// Extract the begin hash from the block locator, if one was specified,
// to use for filtering duplicate getheaders requests.
var beginHash *chainhash.Hash
if len(locator) > 0 {
beginHash = locator[0]
}
// Filt... | [
"func",
"(",
"p",
"*",
"Peer",
")",
"PushGetHeadersMsg",
"(",
"locator",
"blockchain",
".",
"BlockLocator",
",",
"stopHash",
"*",
"chainhash",
".",
"Hash",
")",
"error",
"{",
"// Extract the begin hash from the block locator, if one was specified,",
"// to use for filteri... | // PushGetHeadersMsg sends a getblocks message for the provided block locator
// and stop hash. It will ignore back-to-back duplicate requests.
//
// This function is safe for concurrent access. | [
"PushGetHeadersMsg",
"sends",
"a",
"getblocks",
"message",
"for",
"the",
"provided",
"block",
"locator",
"and",
"stop",
"hash",
".",
"It",
"will",
"ignore",
"back",
"-",
"to",
"-",
"back",
"duplicate",
"requests",
".",
"This",
"function",
"is",
"safe",
"for"... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L895-L934 |
163,644 | btcsuite/btcd | peer/peer.go | PushRejectMsg | func (p *Peer) PushRejectMsg(command string, code wire.RejectCode, reason string, hash *chainhash.Hash, wait bool) {
// Don't bother sending the reject message if the protocol version
// is too low.
if p.VersionKnown() && p.ProtocolVersion() < wire.RejectVersion {
return
}
msg := wire.NewMsgReject(command, code... | go | func (p *Peer) PushRejectMsg(command string, code wire.RejectCode, reason string, hash *chainhash.Hash, wait bool) {
// Don't bother sending the reject message if the protocol version
// is too low.
if p.VersionKnown() && p.ProtocolVersion() < wire.RejectVersion {
return
}
msg := wire.NewMsgReject(command, code... | [
"func",
"(",
"p",
"*",
"Peer",
")",
"PushRejectMsg",
"(",
"command",
"string",
",",
"code",
"wire",
".",
"RejectCode",
",",
"reason",
"string",
",",
"hash",
"*",
"chainhash",
".",
"Hash",
",",
"wait",
"bool",
")",
"{",
"// Don't bother sending the reject mes... | // PushRejectMsg sends a reject message for the provided command, reject code,
// reject reason, and hash. The hash will only be used when the command is a tx
// or block and should be nil in other cases. The wait parameter will cause the
// function to block until the reject message has actually been sent.
//
// Thi... | [
"PushRejectMsg",
"sends",
"a",
"reject",
"message",
"for",
"the",
"provided",
"command",
"reject",
"code",
"reject",
"reason",
"and",
"hash",
".",
"The",
"hash",
"will",
"only",
"be",
"used",
"when",
"the",
"command",
"is",
"a",
"tx",
"or",
"block",
"and",... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L942-L970 |
163,645 | btcsuite/btcd | peer/peer.go | readMessage | func (p *Peer) readMessage(encoding wire.MessageEncoding) (wire.Message, []byte, error) {
n, msg, buf, err := wire.ReadMessageWithEncodingN(p.conn,
p.ProtocolVersion(), p.cfg.ChainParams.Net, encoding)
atomic.AddUint64(&p.bytesReceived, uint64(n))
if p.cfg.Listeners.OnRead != nil {
p.cfg.Listeners.OnRead(p, n, m... | go | func (p *Peer) readMessage(encoding wire.MessageEncoding) (wire.Message, []byte, error) {
n, msg, buf, err := wire.ReadMessageWithEncodingN(p.conn,
p.ProtocolVersion(), p.cfg.ChainParams.Net, encoding)
atomic.AddUint64(&p.bytesReceived, uint64(n))
if p.cfg.Listeners.OnRead != nil {
p.cfg.Listeners.OnRead(p, n, m... | [
"func",
"(",
"p",
"*",
"Peer",
")",
"readMessage",
"(",
"encoding",
"wire",
".",
"MessageEncoding",
")",
"(",
"wire",
".",
"Message",
",",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"n",
",",
"msg",
",",
"buf",
",",
"err",
":=",
"wire",
".",
"Read... | // readMessage reads the next bitcoin message from the peer with logging. | [
"readMessage",
"reads",
"the",
"next",
"bitcoin",
"message",
"from",
"the",
"peer",
"with",
"logging",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L1008-L1038 |
163,646 | btcsuite/btcd | peer/peer.go | writeMessage | func (p *Peer) writeMessage(msg wire.Message, enc wire.MessageEncoding) error {
// Don't do anything if we're disconnecting.
if atomic.LoadInt32(&p.disconnect) != 0 {
return nil
}
// Use closures to log expensive operations so they are only run when
// the logging level requires it.
log.Debugf("%v", newLogClos... | go | func (p *Peer) writeMessage(msg wire.Message, enc wire.MessageEncoding) error {
// Don't do anything if we're disconnecting.
if atomic.LoadInt32(&p.disconnect) != 0 {
return nil
}
// Use closures to log expensive operations so they are only run when
// the logging level requires it.
log.Debugf("%v", newLogClos... | [
"func",
"(",
"p",
"*",
"Peer",
")",
"writeMessage",
"(",
"msg",
"wire",
".",
"Message",
",",
"enc",
"wire",
".",
"MessageEncoding",
")",
"error",
"{",
"// Don't do anything if we're disconnecting.",
"if",
"atomic",
".",
"LoadInt32",
"(",
"&",
"p",
".",
"disc... | // writeMessage sends a bitcoin message to the peer with logging. | [
"writeMessage",
"sends",
"a",
"bitcoin",
"message",
"to",
"the",
"peer",
"with",
"logging",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L1041-L1079 |
163,647 | btcsuite/btcd | peer/peer.go | isAllowedReadError | func (p *Peer) isAllowedReadError(err error) bool {
// Only allow read errors in regression test mode.
if p.cfg.ChainParams.Net != wire.TestNet {
return false
}
// Don't allow the error if it's not specifically a malformed message error.
if _, ok := err.(*wire.MessageError); !ok {
return false
}
// Don't a... | go | func (p *Peer) isAllowedReadError(err error) bool {
// Only allow read errors in regression test mode.
if p.cfg.ChainParams.Net != wire.TestNet {
return false
}
// Don't allow the error if it's not specifically a malformed message error.
if _, ok := err.(*wire.MessageError); !ok {
return false
}
// Don't a... | [
"func",
"(",
"p",
"*",
"Peer",
")",
"isAllowedReadError",
"(",
"err",
"error",
")",
"bool",
"{",
"// Only allow read errors in regression test mode.",
"if",
"p",
".",
"cfg",
".",
"ChainParams",
".",
"Net",
"!=",
"wire",
".",
"TestNet",
"{",
"return",
"false",
... | // isAllowedReadError returns whether or not the passed error is allowed without
// disconnecting the peer. In particular, regression tests need to be allowed
// to send malformed messages without the peer being disconnected. | [
"isAllowedReadError",
"returns",
"whether",
"or",
"not",
"the",
"passed",
"error",
"is",
"allowed",
"without",
"disconnecting",
"the",
"peer",
".",
"In",
"particular",
"regression",
"tests",
"need",
"to",
"be",
"allowed",
"to",
"send",
"malformed",
"messages",
"... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L1084-L1108 |
163,648 | btcsuite/btcd | peer/peer.go | maybeAddDeadline | func (p *Peer) maybeAddDeadline(pendingResponses map[string]time.Time, msgCmd string) {
// Setup a deadline for each message being sent that expects a response.
//
// NOTE: Pings are intentionally ignored here since they are typically
// sent asynchronously and as a result of a long backlock of messages,
// such a... | go | func (p *Peer) maybeAddDeadline(pendingResponses map[string]time.Time, msgCmd string) {
// Setup a deadline for each message being sent that expects a response.
//
// NOTE: Pings are intentionally ignored here since they are typically
// sent asynchronously and as a result of a long backlock of messages,
// such a... | [
"func",
"(",
"p",
"*",
"Peer",
")",
"maybeAddDeadline",
"(",
"pendingResponses",
"map",
"[",
"string",
"]",
"time",
".",
"Time",
",",
"msgCmd",
"string",
")",
"{",
"// Setup a deadline for each message being sent that expects a response.",
"//",
"// NOTE: Pings are inte... | // maybeAddDeadline potentially adds a deadline for the appropriate expected
// response for the passed wire protocol command to the pending responses map. | [
"maybeAddDeadline",
"potentially",
"adds",
"a",
"deadline",
"for",
"the",
"appropriate",
"expected",
"response",
"for",
"the",
"passed",
"wire",
"protocol",
"command",
"to",
"the",
"pending",
"responses",
"map",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L1134-L1169 |
163,649 | btcsuite/btcd | peer/peer.go | stallHandler | func (p *Peer) stallHandler() {
// These variables are used to adjust the deadline times forward by the
// time it takes callbacks to execute. This is done because new
// messages aren't read until the previous one is finished processing
// (which includes callbacks), so the deadline for receiving a response
// f... | go | func (p *Peer) stallHandler() {
// These variables are used to adjust the deadline times forward by the
// time it takes callbacks to execute. This is done because new
// messages aren't read until the previous one is finished processing
// (which includes callbacks), so the deadline for receiving a response
// f... | [
"func",
"(",
"p",
"*",
"Peer",
")",
"stallHandler",
"(",
")",
"{",
"// These variables are used to adjust the deadline times forward by the",
"// time it takes callbacks to execute. This is done because new",
"// messages aren't read until the previous one is finished processing",
"// (wh... | // stallHandler handles stall detection for the peer. This entails keeping
// track of expected responses and assigning them deadlines while accounting for
// the time spent in callbacks. It must be run as a goroutine. | [
"stallHandler",
"handles",
"stall",
"detection",
"for",
"the",
"peer",
".",
"This",
"entails",
"keeping",
"track",
"of",
"expected",
"responses",
"and",
"assigning",
"them",
"deadlines",
"while",
"accounting",
"for",
"the",
"time",
"spent",
"in",
"callbacks",
".... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L1174-L1317 |
163,650 | btcsuite/btcd | peer/peer.go | shouldLogWriteError | func (p *Peer) shouldLogWriteError(err error) bool {
// No logging when the peer is being forcibly disconnected.
if atomic.LoadInt32(&p.disconnect) != 0 {
return false
}
// No logging when the remote peer has been disconnected.
if err == io.EOF {
return false
}
if opErr, ok := err.(*net.OpError); ok && !opE... | go | func (p *Peer) shouldLogWriteError(err error) bool {
// No logging when the peer is being forcibly disconnected.
if atomic.LoadInt32(&p.disconnect) != 0 {
return false
}
// No logging when the remote peer has been disconnected.
if err == io.EOF {
return false
}
if opErr, ok := err.(*net.OpError); ok && !opE... | [
"func",
"(",
"p",
"*",
"Peer",
")",
"shouldLogWriteError",
"(",
"err",
"error",
")",
"bool",
"{",
"// No logging when the peer is being forcibly disconnected.",
"if",
"atomic",
".",
"LoadInt32",
"(",
"&",
"p",
".",
"disconnect",
")",
"!=",
"0",
"{",
"return",
... | // shouldLogWriteError returns whether or not the passed error, which is
// expected to have come from writing to the remote peer in the outHandler,
// should be logged. | [
"shouldLogWriteError",
"returns",
"whether",
"or",
"not",
"the",
"passed",
"error",
"which",
"is",
"expected",
"to",
"have",
"come",
"from",
"writing",
"to",
"the",
"remote",
"peer",
"in",
"the",
"outHandler",
"should",
"be",
"logged",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L1693-L1708 |
163,651 | btcsuite/btcd | peer/peer.go | outHandler | func (p *Peer) outHandler() {
out:
for {
select {
case msg := <-p.sendQueue:
switch m := msg.msg.(type) {
case *wire.MsgPing:
// Only expects a pong message in later protocol
// versions. Also set up statistics.
if p.ProtocolVersion() > wire.BIP0031Version {
p.statsMtx.Lock()
p.lastPin... | go | func (p *Peer) outHandler() {
out:
for {
select {
case msg := <-p.sendQueue:
switch m := msg.msg.(type) {
case *wire.MsgPing:
// Only expects a pong message in later protocol
// versions. Also set up statistics.
if p.ProtocolVersion() > wire.BIP0031Version {
p.statsMtx.Lock()
p.lastPin... | [
"func",
"(",
"p",
"*",
"Peer",
")",
"outHandler",
"(",
")",
"{",
"out",
":",
"for",
"{",
"select",
"{",
"case",
"msg",
":=",
"<-",
"p",
".",
"sendQueue",
":",
"switch",
"m",
":=",
"msg",
".",
"msg",
".",
"(",
"type",
")",
"{",
"case",
"*",
"w... | // outHandler handles all outgoing messages for the peer. It must be run as a
// goroutine. It uses a buffered channel to serialize output messages while
// allowing the sender to continue running asynchronously. | [
"outHandler",
"handles",
"all",
"outgoing",
"messages",
"for",
"the",
"peer",
".",
"It",
"must",
"be",
"run",
"as",
"a",
"goroutine",
".",
"It",
"uses",
"a",
"buffered",
"channel",
"to",
"serialize",
"output",
"messages",
"while",
"allowing",
"the",
"sender"... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L1713-L1781 |
163,652 | btcsuite/btcd | peer/peer.go | pingHandler | func (p *Peer) pingHandler() {
pingTicker := time.NewTicker(pingInterval)
defer pingTicker.Stop()
out:
for {
select {
case <-pingTicker.C:
nonce, err := wire.RandomUint64()
if err != nil {
log.Errorf("Not sending ping to %s: %v", p, err)
continue
}
p.QueueMessage(wire.NewMsgPing(nonce), nil)... | go | func (p *Peer) pingHandler() {
pingTicker := time.NewTicker(pingInterval)
defer pingTicker.Stop()
out:
for {
select {
case <-pingTicker.C:
nonce, err := wire.RandomUint64()
if err != nil {
log.Errorf("Not sending ping to %s: %v", p, err)
continue
}
p.QueueMessage(wire.NewMsgPing(nonce), nil)... | [
"func",
"(",
"p",
"*",
"Peer",
")",
"pingHandler",
"(",
")",
"{",
"pingTicker",
":=",
"time",
".",
"NewTicker",
"(",
"pingInterval",
")",
"\n",
"defer",
"pingTicker",
".",
"Stop",
"(",
")",
"\n\n",
"out",
":",
"for",
"{",
"select",
"{",
"case",
"<-",... | // pingHandler periodically pings the peer. It must be run as a goroutine. | [
"pingHandler",
"periodically",
"pings",
"the",
"peer",
".",
"It",
"must",
"be",
"run",
"as",
"a",
"goroutine",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L1784-L1803 |
163,653 | btcsuite/btcd | peer/peer.go | QueueMessage | func (p *Peer) QueueMessage(msg wire.Message, doneChan chan<- struct{}) {
p.QueueMessageWithEncoding(msg, doneChan, wire.BaseEncoding)
} | go | func (p *Peer) QueueMessage(msg wire.Message, doneChan chan<- struct{}) {
p.QueueMessageWithEncoding(msg, doneChan, wire.BaseEncoding)
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"QueueMessage",
"(",
"msg",
"wire",
".",
"Message",
",",
"doneChan",
"chan",
"<-",
"struct",
"{",
"}",
")",
"{",
"p",
".",
"QueueMessageWithEncoding",
"(",
"msg",
",",
"doneChan",
",",
"wire",
".",
"BaseEncoding",
")... | // QueueMessage adds the passed bitcoin message to the peer send queue.
//
// This function is safe for concurrent access. | [
"QueueMessage",
"adds",
"the",
"passed",
"bitcoin",
"message",
"to",
"the",
"peer",
"send",
"queue",
".",
"This",
"function",
"is",
"safe",
"for",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L1808-L1810 |
163,654 | btcsuite/btcd | peer/peer.go | QueueInventory | func (p *Peer) QueueInventory(invVect *wire.InvVect) {
// Don't add the inventory to the send queue if the peer is already
// known to have it.
if p.knownInventory.Exists(invVect) {
return
}
// Avoid risk of deadlock if goroutine already exited. The goroutine
// we will be sending to hangs around until it kno... | go | func (p *Peer) QueueInventory(invVect *wire.InvVect) {
// Don't add the inventory to the send queue if the peer is already
// known to have it.
if p.knownInventory.Exists(invVect) {
return
}
// Avoid risk of deadlock if goroutine already exited. The goroutine
// we will be sending to hangs around until it kno... | [
"func",
"(",
"p",
"*",
"Peer",
")",
"QueueInventory",
"(",
"invVect",
"*",
"wire",
".",
"InvVect",
")",
"{",
"// Don't add the inventory to the send queue if the peer is already",
"// known to have it.",
"if",
"p",
".",
"knownInventory",
".",
"Exists",
"(",
"invVect",... | // QueueInventory adds the passed inventory to the inventory send queue which
// might not be sent right away, rather it is trickled to the peer in batches.
// Inventory that the peer is already known to have is ignored.
//
// This function is safe for concurrent access. | [
"QueueInventory",
"adds",
"the",
"passed",
"inventory",
"to",
"the",
"inventory",
"send",
"queue",
"which",
"might",
"not",
"be",
"sent",
"right",
"away",
"rather",
"it",
"is",
"trickled",
"to",
"the",
"peer",
"in",
"batches",
".",
"Inventory",
"that",
"the"... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L1840-L1855 |
163,655 | btcsuite/btcd | peer/peer.go | Connected | func (p *Peer) Connected() bool {
return atomic.LoadInt32(&p.connected) != 0 &&
atomic.LoadInt32(&p.disconnect) == 0
} | go | func (p *Peer) Connected() bool {
return atomic.LoadInt32(&p.connected) != 0 &&
atomic.LoadInt32(&p.disconnect) == 0
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"Connected",
"(",
")",
"bool",
"{",
"return",
"atomic",
".",
"LoadInt32",
"(",
"&",
"p",
".",
"connected",
")",
"!=",
"0",
"&&",
"atomic",
".",
"LoadInt32",
"(",
"&",
"p",
".",
"disconnect",
")",
"==",
"0",
"\n... | // Connected returns whether or not the peer is currently connected.
//
// This function is safe for concurrent access. | [
"Connected",
"returns",
"whether",
"or",
"not",
"the",
"peer",
"is",
"currently",
"connected",
".",
"This",
"function",
"is",
"safe",
"for",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L1860-L1863 |
163,656 | btcsuite/btcd | peer/peer.go | Disconnect | func (p *Peer) Disconnect() {
if atomic.AddInt32(&p.disconnect, 1) != 1 {
return
}
log.Tracef("Disconnecting %s", p)
if atomic.LoadInt32(&p.connected) != 0 {
p.conn.Close()
}
close(p.quit)
} | go | func (p *Peer) Disconnect() {
if atomic.AddInt32(&p.disconnect, 1) != 1 {
return
}
log.Tracef("Disconnecting %s", p)
if atomic.LoadInt32(&p.connected) != 0 {
p.conn.Close()
}
close(p.quit)
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"Disconnect",
"(",
")",
"{",
"if",
"atomic",
".",
"AddInt32",
"(",
"&",
"p",
".",
"disconnect",
",",
"1",
")",
"!=",
"1",
"{",
"return",
"\n",
"}",
"\n\n",
"log",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"p",
"... | // Disconnect disconnects the peer by closing the connection. Calling this
// function when the peer is already disconnected or in the process of
// disconnecting will have no effect. | [
"Disconnect",
"disconnects",
"the",
"peer",
"by",
"closing",
"the",
"connection",
".",
"Calling",
"this",
"function",
"when",
"the",
"peer",
"is",
"already",
"disconnected",
"or",
"in",
"the",
"process",
"of",
"disconnecting",
"will",
"have",
"no",
"effect",
"... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L1868-L1878 |
163,657 | btcsuite/btcd | peer/peer.go | readRemoteVersionMsg | func (p *Peer) readRemoteVersionMsg() error {
// Read their version message.
remoteMsg, _, err := p.readMessage(wire.LatestEncoding)
if err != nil {
return err
}
// Notify and disconnect clients if the first message is not a version
// message.
msg, ok := remoteMsg.(*wire.MsgVersion)
if !ok {
reason := "a ... | go | func (p *Peer) readRemoteVersionMsg() error {
// Read their version message.
remoteMsg, _, err := p.readMessage(wire.LatestEncoding)
if err != nil {
return err
}
// Notify and disconnect clients if the first message is not a version
// message.
msg, ok := remoteMsg.(*wire.MsgVersion)
if !ok {
reason := "a ... | [
"func",
"(",
"p",
"*",
"Peer",
")",
"readRemoteVersionMsg",
"(",
")",
"error",
"{",
"// Read their version message.",
"remoteMsg",
",",
"_",
",",
"err",
":=",
"p",
".",
"readMessage",
"(",
"wire",
".",
"LatestEncoding",
")",
"\n",
"if",
"err",
"!=",
"nil",... | // readRemoteVersionMsg waits for the next message to arrive from the remote
// peer. If the next message is not a version message or the version is not
// acceptable then return an error. | [
"readRemoteVersionMsg",
"waits",
"for",
"the",
"next",
"message",
"to",
"arrive",
"from",
"the",
"remote",
"peer",
".",
"If",
"the",
"next",
"message",
"is",
"not",
"a",
"version",
"message",
"or",
"the",
"version",
"is",
"not",
"acceptable",
"then",
"return... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L1883-L1975 |
163,658 | btcsuite/btcd | peer/peer.go | localVersionMsg | func (p *Peer) localVersionMsg() (*wire.MsgVersion, error) {
var blockNum int32
if p.cfg.NewestBlock != nil {
var err error
_, blockNum, err = p.cfg.NewestBlock()
if err != nil {
return nil, err
}
}
theirNA := p.na
// If we are behind a proxy and the connection comes from the proxy then
// we return ... | go | func (p *Peer) localVersionMsg() (*wire.MsgVersion, error) {
var blockNum int32
if p.cfg.NewestBlock != nil {
var err error
_, blockNum, err = p.cfg.NewestBlock()
if err != nil {
return nil, err
}
}
theirNA := p.na
// If we are behind a proxy and the connection comes from the proxy then
// we return ... | [
"func",
"(",
"p",
"*",
"Peer",
")",
"localVersionMsg",
"(",
")",
"(",
"*",
"wire",
".",
"MsgVersion",
",",
"error",
")",
"{",
"var",
"blockNum",
"int32",
"\n",
"if",
"p",
".",
"cfg",
".",
"NewestBlock",
"!=",
"nil",
"{",
"var",
"err",
"error",
"\n"... | // localVersionMsg creates a version message that can be used to send to the
// remote peer. | [
"localVersionMsg",
"creates",
"a",
"version",
"message",
"that",
"can",
"be",
"used",
"to",
"send",
"to",
"the",
"remote",
"peer",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L1979-L2037 |
163,659 | btcsuite/btcd | peer/peer.go | writeLocalVersionMsg | func (p *Peer) writeLocalVersionMsg() error {
localVerMsg, err := p.localVersionMsg()
if err != nil {
return err
}
return p.writeMessage(localVerMsg, wire.LatestEncoding)
} | go | func (p *Peer) writeLocalVersionMsg() error {
localVerMsg, err := p.localVersionMsg()
if err != nil {
return err
}
return p.writeMessage(localVerMsg, wire.LatestEncoding)
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"writeLocalVersionMsg",
"(",
")",
"error",
"{",
"localVerMsg",
",",
"err",
":=",
"p",
".",
"localVersionMsg",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"p",
".",
... | // writeLocalVersionMsg writes our version message to the remote peer. | [
"writeLocalVersionMsg",
"writes",
"our",
"version",
"message",
"to",
"the",
"remote",
"peer",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L2040-L2047 |
163,660 | btcsuite/btcd | peer/peer.go | negotiateInboundProtocol | func (p *Peer) negotiateInboundProtocol() error {
if err := p.readRemoteVersionMsg(); err != nil {
return err
}
return p.writeLocalVersionMsg()
} | go | func (p *Peer) negotiateInboundProtocol() error {
if err := p.readRemoteVersionMsg(); err != nil {
return err
}
return p.writeLocalVersionMsg()
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"negotiateInboundProtocol",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"p",
".",
"readRemoteVersionMsg",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"p",
".",
"writeLocalVers... | // negotiateInboundProtocol waits to receive a version message from the peer
// then sends our version message. If the events do not occur in that order then
// it returns an error. | [
"negotiateInboundProtocol",
"waits",
"to",
"receive",
"a",
"version",
"message",
"from",
"the",
"peer",
"then",
"sends",
"our",
"version",
"message",
".",
"If",
"the",
"events",
"do",
"not",
"occur",
"in",
"that",
"order",
"then",
"it",
"returns",
"an",
"err... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L2052-L2058 |
163,661 | btcsuite/btcd | peer/peer.go | negotiateOutboundProtocol | func (p *Peer) negotiateOutboundProtocol() error {
if err := p.writeLocalVersionMsg(); err != nil {
return err
}
return p.readRemoteVersionMsg()
} | go | func (p *Peer) negotiateOutboundProtocol() error {
if err := p.writeLocalVersionMsg(); err != nil {
return err
}
return p.readRemoteVersionMsg()
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"negotiateOutboundProtocol",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"p",
".",
"writeLocalVersionMsg",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"p",
".",
"readRemoteVer... | // negotiateOutboundProtocol sends our version message then waits to receive a
// version message from the peer. If the events do not occur in that order then
// it returns an error. | [
"negotiateOutboundProtocol",
"sends",
"our",
"version",
"message",
"then",
"waits",
"to",
"receive",
"a",
"version",
"message",
"from",
"the",
"peer",
".",
"If",
"the",
"events",
"do",
"not",
"occur",
"in",
"that",
"order",
"then",
"it",
"returns",
"an",
"er... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L2063-L2069 |
163,662 | btcsuite/btcd | peer/peer.go | AssociateConnection | func (p *Peer) AssociateConnection(conn net.Conn) {
// Already connected?
if !atomic.CompareAndSwapInt32(&p.connected, 0, 1) {
return
}
p.conn = conn
p.timeConnected = time.Now()
if p.inbound {
p.addr = p.conn.RemoteAddr().String()
// Set up a NetAddress for the peer to be used with AddrManager. We
//... | go | func (p *Peer) AssociateConnection(conn net.Conn) {
// Already connected?
if !atomic.CompareAndSwapInt32(&p.connected, 0, 1) {
return
}
p.conn = conn
p.timeConnected = time.Now()
if p.inbound {
p.addr = p.conn.RemoteAddr().String()
// Set up a NetAddress for the peer to be used with AddrManager. We
//... | [
"func",
"(",
"p",
"*",
"Peer",
")",
"AssociateConnection",
"(",
"conn",
"net",
".",
"Conn",
")",
"{",
"// Already connected?",
"if",
"!",
"atomic",
".",
"CompareAndSwapInt32",
"(",
"&",
"p",
".",
"connected",
",",
"0",
",",
"1",
")",
"{",
"return",
"\n... | // AssociateConnection associates the given conn to the peer. Calling this
// function when the peer is already connected will have no effect. | [
"AssociateConnection",
"associates",
"the",
"given",
"conn",
"to",
"the",
"peer",
".",
"Calling",
"this",
"function",
"when",
"the",
"peer",
"is",
"already",
"connected",
"will",
"have",
"no",
"effect",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L2112-L2142 |
163,663 | btcsuite/btcd | peer/peer.go | newPeerBase | func newPeerBase(origCfg *Config, inbound bool) *Peer {
// Default to the max supported protocol version if not specified by the
// caller.
cfg := *origCfg // Copy to avoid mutating caller.
if cfg.ProtocolVersion == 0 {
cfg.ProtocolVersion = MaxProtocolVersion
}
// Set the chain parameters to testnet if the ca... | go | func newPeerBase(origCfg *Config, inbound bool) *Peer {
// Default to the max supported protocol version if not specified by the
// caller.
cfg := *origCfg // Copy to avoid mutating caller.
if cfg.ProtocolVersion == 0 {
cfg.ProtocolVersion = MaxProtocolVersion
}
// Set the chain parameters to testnet if the ca... | [
"func",
"newPeerBase",
"(",
"origCfg",
"*",
"Config",
",",
"inbound",
"bool",
")",
"*",
"Peer",
"{",
"// Default to the max supported protocol version if not specified by the",
"// caller.",
"cfg",
":=",
"*",
"origCfg",
"// Copy to avoid mutating caller.",
"\n",
"if",
"cf... | // newPeerBase returns a new base bitcoin peer based on the inbound flag. This
// is used by the NewInboundPeer and NewOutboundPeer functions to perform base
// setup needed by both types of peers. | [
"newPeerBase",
"returns",
"a",
"new",
"base",
"bitcoin",
"peer",
"based",
"on",
"the",
"inbound",
"flag",
".",
"This",
"is",
"used",
"by",
"the",
"NewInboundPeer",
"and",
"NewOutboundPeer",
"functions",
"to",
"perform",
"base",
"setup",
"needed",
"by",
"both",... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L2155-L2191 |
163,664 | btcsuite/btcd | peer/peer.go | NewOutboundPeer | func NewOutboundPeer(cfg *Config, addr string) (*Peer, error) {
p := newPeerBase(cfg, false)
p.addr = addr
host, portStr, err := net.SplitHostPort(addr)
if err != nil {
return nil, err
}
port, err := strconv.ParseUint(portStr, 10, 16)
if err != nil {
return nil, err
}
if cfg.HostToNetAddress != nil {
... | go | func NewOutboundPeer(cfg *Config, addr string) (*Peer, error) {
p := newPeerBase(cfg, false)
p.addr = addr
host, portStr, err := net.SplitHostPort(addr)
if err != nil {
return nil, err
}
port, err := strconv.ParseUint(portStr, 10, 16)
if err != nil {
return nil, err
}
if cfg.HostToNetAddress != nil {
... | [
"func",
"NewOutboundPeer",
"(",
"cfg",
"*",
"Config",
",",
"addr",
"string",
")",
"(",
"*",
"Peer",
",",
"error",
")",
"{",
"p",
":=",
"newPeerBase",
"(",
"cfg",
",",
"false",
")",
"\n",
"p",
".",
"addr",
"=",
"addr",
"\n\n",
"host",
",",
"portStr"... | // NewOutboundPeer returns a new outbound bitcoin peer. | [
"NewOutboundPeer",
"returns",
"a",
"new",
"outbound",
"bitcoin",
"peer",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/peer.go#L2200-L2225 |
163,665 | btcsuite/btcd | wire/message.go | makeEmptyMessage | func makeEmptyMessage(command string) (Message, error) {
var msg Message
switch command {
case CmdVersion:
msg = &MsgVersion{}
case CmdVerAck:
msg = &MsgVerAck{}
case CmdGetAddr:
msg = &MsgGetAddr{}
case CmdAddr:
msg = &MsgAddr{}
case CmdGetBlocks:
msg = &MsgGetBlocks{}
case CmdBlock:
msg = &Ms... | go | func makeEmptyMessage(command string) (Message, error) {
var msg Message
switch command {
case CmdVersion:
msg = &MsgVersion{}
case CmdVerAck:
msg = &MsgVerAck{}
case CmdGetAddr:
msg = &MsgGetAddr{}
case CmdAddr:
msg = &MsgAddr{}
case CmdGetBlocks:
msg = &MsgGetBlocks{}
case CmdBlock:
msg = &Ms... | [
"func",
"makeEmptyMessage",
"(",
"command",
"string",
")",
"(",
"Message",
",",
"error",
")",
"{",
"var",
"msg",
"Message",
"\n",
"switch",
"command",
"{",
"case",
"CmdVersion",
":",
"msg",
"=",
"&",
"MsgVersion",
"{",
"}",
"\n\n",
"case",
"CmdVerAck",
"... | // makeEmptyMessage creates a message of the appropriate concrete type based
// on the command. | [
"makeEmptyMessage",
"creates",
"a",
"message",
"of",
"the",
"appropriate",
"concrete",
"type",
"based",
"on",
"the",
"command",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/wire/message.go#L93-L187 |
163,666 | btcsuite/btcd | wire/message.go | readMessageHeader | func readMessageHeader(r io.Reader) (int, *messageHeader, error) {
// Since readElements doesn't return the amount of bytes read, attempt
// to read the entire header into a buffer first in case there is a
// short read so the proper amount of read bytes are known. This works
// since the header is a fixed size.
... | go | func readMessageHeader(r io.Reader) (int, *messageHeader, error) {
// Since readElements doesn't return the amount of bytes read, attempt
// to read the entire header into a buffer first in case there is a
// short read so the proper amount of read bytes are known. This works
// since the header is a fixed size.
... | [
"func",
"readMessageHeader",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"int",
",",
"*",
"messageHeader",
",",
"error",
")",
"{",
"// Since readElements doesn't return the amount of bytes read, attempt",
"// to read the entire header into a buffer first in case there is a",
"// s... | // readMessageHeader reads a bitcoin message header from r. | [
"readMessageHeader",
"reads",
"a",
"bitcoin",
"message",
"header",
"from",
"r",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/wire/message.go#L198-L219 |
163,667 | btcsuite/btcd | wire/message.go | discardInput | func discardInput(r io.Reader, n uint32) {
maxSize := uint32(10 * 1024) // 10k at a time
numReads := n / maxSize
bytesRemaining := n % maxSize
if n > 0 {
buf := make([]byte, maxSize)
for i := uint32(0); i < numReads; i++ {
io.ReadFull(r, buf)
}
}
if bytesRemaining > 0 {
buf := make([]byte, bytesRemaini... | go | func discardInput(r io.Reader, n uint32) {
maxSize := uint32(10 * 1024) // 10k at a time
numReads := n / maxSize
bytesRemaining := n % maxSize
if n > 0 {
buf := make([]byte, maxSize)
for i := uint32(0); i < numReads; i++ {
io.ReadFull(r, buf)
}
}
if bytesRemaining > 0 {
buf := make([]byte, bytesRemaini... | [
"func",
"discardInput",
"(",
"r",
"io",
".",
"Reader",
",",
"n",
"uint32",
")",
"{",
"maxSize",
":=",
"uint32",
"(",
"10",
"*",
"1024",
")",
"// 10k at a time",
"\n",
"numReads",
":=",
"n",
"/",
"maxSize",
"\n",
"bytesRemaining",
":=",
"n",
"%",
"maxSi... | // discardInput reads n bytes from reader r in chunks and discards the read
// bytes. This is used to skip payloads when various errors occur and helps
// prevent rogue nodes from causing massive memory allocation through forging
// header length. | [
"discardInput",
"reads",
"n",
"bytes",
"from",
"reader",
"r",
"in",
"chunks",
"and",
"discards",
"the",
"read",
"bytes",
".",
"This",
"is",
"used",
"to",
"skip",
"payloads",
"when",
"various",
"errors",
"occur",
"and",
"helps",
"prevent",
"rogue",
"nodes",
... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/wire/message.go#L225-L239 |
163,668 | btcsuite/btcd | wire/message.go | WriteMessageN | func WriteMessageN(w io.Writer, msg Message, pver uint32, btcnet BitcoinNet) (int, error) {
return WriteMessageWithEncodingN(w, msg, pver, btcnet, BaseEncoding)
} | go | func WriteMessageN(w io.Writer, msg Message, pver uint32, btcnet BitcoinNet) (int, error) {
return WriteMessageWithEncodingN(w, msg, pver, btcnet, BaseEncoding)
} | [
"func",
"WriteMessageN",
"(",
"w",
"io",
".",
"Writer",
",",
"msg",
"Message",
",",
"pver",
"uint32",
",",
"btcnet",
"BitcoinNet",
")",
"(",
"int",
",",
"error",
")",
"{",
"return",
"WriteMessageWithEncodingN",
"(",
"w",
",",
"msg",
",",
"pver",
",",
"... | // WriteMessageN writes a bitcoin Message to w including the necessary header
// information and returns the number of bytes written. This function is the
// same as WriteMessage except it also returns the number of bytes written. | [
"WriteMessageN",
"writes",
"a",
"bitcoin",
"Message",
"to",
"w",
"including",
"the",
"necessary",
"header",
"information",
"and",
"returns",
"the",
"number",
"of",
"bytes",
"written",
".",
"This",
"function",
"is",
"the",
"same",
"as",
"WriteMessage",
"except",
... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/wire/message.go#L244-L246 |
163,669 | btcsuite/btcd | wire/message.go | WriteMessage | func WriteMessage(w io.Writer, msg Message, pver uint32, btcnet BitcoinNet) error {
_, err := WriteMessageN(w, msg, pver, btcnet)
return err
} | go | func WriteMessage(w io.Writer, msg Message, pver uint32, btcnet BitcoinNet) error {
_, err := WriteMessageN(w, msg, pver, btcnet)
return err
} | [
"func",
"WriteMessage",
"(",
"w",
"io",
".",
"Writer",
",",
"msg",
"Message",
",",
"pver",
"uint32",
",",
"btcnet",
"BitcoinNet",
")",
"error",
"{",
"_",
",",
"err",
":=",
"WriteMessageN",
"(",
"w",
",",
"msg",
",",
"pver",
",",
"btcnet",
")",
"\n",
... | // WriteMessage writes a bitcoin Message to w including the necessary header
// information. This function is the same as WriteMessageN except it doesn't
// doesn't return the number of bytes written. This function is mainly provided
// for backwards compatibility with the original API, but it's also useful for
// ca... | [
"WriteMessage",
"writes",
"a",
"bitcoin",
"Message",
"to",
"w",
"including",
"the",
"necessary",
"header",
"information",
".",
"This",
"function",
"is",
"the",
"same",
"as",
"WriteMessageN",
"except",
"it",
"doesn",
"t",
"doesn",
"t",
"return",
"the",
"number"... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/wire/message.go#L253-L256 |
163,670 | btcsuite/btcd | wire/message.go | WriteMessageWithEncodingN | func WriteMessageWithEncodingN(w io.Writer, msg Message, pver uint32,
btcnet BitcoinNet, encoding MessageEncoding) (int, error) {
totalBytes := 0
// Enforce max command size.
var command [CommandSize]byte
cmd := msg.Command()
if len(cmd) > CommandSize {
str := fmt.Sprintf("command [%s] is too long [max %v]",
... | go | func WriteMessageWithEncodingN(w io.Writer, msg Message, pver uint32,
btcnet BitcoinNet, encoding MessageEncoding) (int, error) {
totalBytes := 0
// Enforce max command size.
var command [CommandSize]byte
cmd := msg.Command()
if len(cmd) > CommandSize {
str := fmt.Sprintf("command [%s] is too long [max %v]",
... | [
"func",
"WriteMessageWithEncodingN",
"(",
"w",
"io",
".",
"Writer",
",",
"msg",
"Message",
",",
"pver",
"uint32",
",",
"btcnet",
"BitcoinNet",
",",
"encoding",
"MessageEncoding",
")",
"(",
"int",
",",
"error",
")",
"{",
"totalBytes",
":=",
"0",
"\n\n",
"//... | // WriteMessageWithEncodingN writes a bitcoin Message to w including the
// necessary header information and returns the number of bytes written.
// This function is the same as WriteMessageN except it also allows the caller
// to specify the message encoding format to be used when serializing wire
// messages. | [
"WriteMessageWithEncodingN",
"writes",
"a",
"bitcoin",
"Message",
"to",
"w",
"including",
"the",
"necessary",
"header",
"information",
"and",
"returns",
"the",
"number",
"of",
"bytes",
"written",
".",
"This",
"function",
"is",
"the",
"same",
"as",
"WriteMessageN",... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/wire/message.go#L263-L328 |
163,671 | btcsuite/btcd | wire/message.go | ReadMessageWithEncodingN | func ReadMessageWithEncodingN(r io.Reader, pver uint32, btcnet BitcoinNet,
enc MessageEncoding) (int, Message, []byte, error) {
totalBytes := 0
n, hdr, err := readMessageHeader(r)
totalBytes += n
if err != nil {
return totalBytes, nil, nil, err
}
// Enforce maximum message payload.
if hdr.length > MaxMessag... | go | func ReadMessageWithEncodingN(r io.Reader, pver uint32, btcnet BitcoinNet,
enc MessageEncoding) (int, Message, []byte, error) {
totalBytes := 0
n, hdr, err := readMessageHeader(r)
totalBytes += n
if err != nil {
return totalBytes, nil, nil, err
}
// Enforce maximum message payload.
if hdr.length > MaxMessag... | [
"func",
"ReadMessageWithEncodingN",
"(",
"r",
"io",
".",
"Reader",
",",
"pver",
"uint32",
",",
"btcnet",
"BitcoinNet",
",",
"enc",
"MessageEncoding",
")",
"(",
"int",
",",
"Message",
",",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"totalBytes",
":=",
"0",... | // ReadMessageWithEncodingN reads, validates, and parses the next bitcoin Message
// from r for the provided protocol version and bitcoin network. It returns the
// number of bytes read in addition to the parsed Message and raw bytes which
// comprise the message. This function is the same as ReadMessageN except it
/... | [
"ReadMessageWithEncodingN",
"reads",
"validates",
"and",
"parses",
"the",
"next",
"bitcoin",
"Message",
"from",
"r",
"for",
"the",
"provided",
"protocol",
"version",
"and",
"bitcoin",
"network",
".",
"It",
"returns",
"the",
"number",
"of",
"bytes",
"read",
"in",... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/wire/message.go#L336-L416 |
163,672 | btcsuite/btcd | wire/message.go | ReadMessageN | func ReadMessageN(r io.Reader, pver uint32, btcnet BitcoinNet) (int, Message, []byte, error) {
return ReadMessageWithEncodingN(r, pver, btcnet, BaseEncoding)
} | go | func ReadMessageN(r io.Reader, pver uint32, btcnet BitcoinNet) (int, Message, []byte, error) {
return ReadMessageWithEncodingN(r, pver, btcnet, BaseEncoding)
} | [
"func",
"ReadMessageN",
"(",
"r",
"io",
".",
"Reader",
",",
"pver",
"uint32",
",",
"btcnet",
"BitcoinNet",
")",
"(",
"int",
",",
"Message",
",",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"ReadMessageWithEncodingN",
"(",
"r",
",",
"pver",
",",... | // ReadMessageN reads, validates, and parses the next bitcoin Message from r for
// the provided protocol version and bitcoin network. It returns the number of
// bytes read in addition to the parsed Message and raw bytes which comprise the
// message. This function is the same as ReadMessage except it also returns t... | [
"ReadMessageN",
"reads",
"validates",
"and",
"parses",
"the",
"next",
"bitcoin",
"Message",
"from",
"r",
"for",
"the",
"provided",
"protocol",
"version",
"and",
"bitcoin",
"network",
".",
"It",
"returns",
"the",
"number",
"of",
"bytes",
"read",
"in",
"addition... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/wire/message.go#L423-L425 |
163,673 | btcsuite/btcd | wire/message.go | ReadMessage | func ReadMessage(r io.Reader, pver uint32, btcnet BitcoinNet) (Message, []byte, error) {
_, msg, buf, err := ReadMessageN(r, pver, btcnet)
return msg, buf, err
} | go | func ReadMessage(r io.Reader, pver uint32, btcnet BitcoinNet) (Message, []byte, error) {
_, msg, buf, err := ReadMessageN(r, pver, btcnet)
return msg, buf, err
} | [
"func",
"ReadMessage",
"(",
"r",
"io",
".",
"Reader",
",",
"pver",
"uint32",
",",
"btcnet",
"BitcoinNet",
")",
"(",
"Message",
",",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"_",
",",
"msg",
",",
"buf",
",",
"err",
":=",
"ReadMessageN",
"(",
"r",
... | // ReadMessage reads, validates, and parses the next bitcoin Message from r for
// the provided protocol version and bitcoin network. It returns the parsed
// Message and raw bytes which comprise the message. This function only differs
// from ReadMessageN in that it doesn't return the number of bytes read. This
// ... | [
"ReadMessage",
"reads",
"validates",
"and",
"parses",
"the",
"next",
"bitcoin",
"Message",
"from",
"r",
"for",
"the",
"provided",
"protocol",
"version",
"and",
"bitcoin",
"network",
".",
"It",
"returns",
"the",
"parsed",
"Message",
"and",
"raw",
"bytes",
"whic... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/wire/message.go#L433-L436 |
163,674 | btcsuite/btcd | database/internal/treap/treapiter.go | limitIterator | func (iter *Iterator) limitIterator() bool {
if iter.node == nil {
return false
}
node := iter.node
if iter.startKey != nil && bytes.Compare(node.key, iter.startKey) < 0 {
iter.node = nil
return false
}
if iter.limitKey != nil && bytes.Compare(node.key, iter.limitKey) >= 0 {
iter.node = nil
return fal... | go | func (iter *Iterator) limitIterator() bool {
if iter.node == nil {
return false
}
node := iter.node
if iter.startKey != nil && bytes.Compare(node.key, iter.startKey) < 0 {
iter.node = nil
return false
}
if iter.limitKey != nil && bytes.Compare(node.key, iter.limitKey) >= 0 {
iter.node = nil
return fal... | [
"func",
"(",
"iter",
"*",
"Iterator",
")",
"limitIterator",
"(",
")",
"bool",
"{",
"if",
"iter",
".",
"node",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"node",
":=",
"iter",
".",
"node",
"\n",
"if",
"iter",
".",
"startKey",
"!=",
"nil... | // limitIterator clears the current iterator node if it is outside of the range
// specified when the iterator was created. It returns whether the iterator is
// valid. | [
"limitIterator",
"clears",
"the",
"current",
"iterator",
"node",
"if",
"it",
"is",
"outside",
"of",
"the",
"range",
"specified",
"when",
"the",
"iterator",
"was",
"created",
".",
"It",
"returns",
"whether",
"the",
"iterator",
"is",
"valid",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/database/internal/treap/treapiter.go#L25-L42 |
163,675 | btcsuite/btcd | btcjson/chainsvrresults.go | MarshalJSON | func (v *Vin) MarshalJSON() ([]byte, error) {
if v.IsCoinBase() {
coinbaseStruct := struct {
Coinbase string `json:"coinbase"`
Sequence uint32 `json:"sequence"`
Witness []string `json:"witness,omitempty"`
}{
Coinbase: v.Coinbase,
Sequence: v.Sequence,
Witness: v.Witness,
}
return json.M... | go | func (v *Vin) MarshalJSON() ([]byte, error) {
if v.IsCoinBase() {
coinbaseStruct := struct {
Coinbase string `json:"coinbase"`
Sequence uint32 `json:"sequence"`
Witness []string `json:"witness,omitempty"`
}{
Coinbase: v.Coinbase,
Sequence: v.Sequence,
Witness: v.Witness,
}
return json.M... | [
"func",
"(",
"v",
"*",
"Vin",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"v",
".",
"IsCoinBase",
"(",
")",
"{",
"coinbaseStruct",
":=",
"struct",
"{",
"Coinbase",
"string",
"`json:\"coinbase\"`",
"\n",
"Sequence"... | // MarshalJSON provides a custom Marshal method for Vin. | [
"MarshalJSON",
"provides",
"a",
"custom",
"Marshal",
"method",
"for",
"Vin",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/btcjson/chainsvrresults.go#L334-L377 |
163,676 | btcsuite/btcd | wire/msgheaders.go | AddBlockHeader | func (msg *MsgHeaders) AddBlockHeader(bh *BlockHeader) error {
if len(msg.Headers)+1 > MaxBlockHeadersPerMsg {
str := fmt.Sprintf("too many block headers in message [max %v]",
MaxBlockHeadersPerMsg)
return messageError("MsgHeaders.AddBlockHeader", str)
}
msg.Headers = append(msg.Headers, bh)
return nil
} | go | func (msg *MsgHeaders) AddBlockHeader(bh *BlockHeader) error {
if len(msg.Headers)+1 > MaxBlockHeadersPerMsg {
str := fmt.Sprintf("too many block headers in message [max %v]",
MaxBlockHeadersPerMsg)
return messageError("MsgHeaders.AddBlockHeader", str)
}
msg.Headers = append(msg.Headers, bh)
return nil
} | [
"func",
"(",
"msg",
"*",
"MsgHeaders",
")",
"AddBlockHeader",
"(",
"bh",
"*",
"BlockHeader",
")",
"error",
"{",
"if",
"len",
"(",
"msg",
".",
"Headers",
")",
"+",
"1",
">",
"MaxBlockHeadersPerMsg",
"{",
"str",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
... | // AddBlockHeader adds a new block header to the message. | [
"AddBlockHeader",
"adds",
"a",
"new",
"block",
"header",
"to",
"the",
"message",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/wire/msgheaders.go#L26-L35 |
163,677 | btcsuite/btcd | btcd.go | removeRegressionDB | func removeRegressionDB(dbPath string) error {
// Don't do anything if not in regression test mode.
if !cfg.RegressionTest {
return nil
}
// Remove the old regression test database if it already exists.
fi, err := os.Stat(dbPath)
if err == nil {
btcdLog.Infof("Removing regression test database from '%s'", db... | go | func removeRegressionDB(dbPath string) error {
// Don't do anything if not in regression test mode.
if !cfg.RegressionTest {
return nil
}
// Remove the old regression test database if it already exists.
fi, err := os.Stat(dbPath)
if err == nil {
btcdLog.Infof("Removing regression test database from '%s'", db... | [
"func",
"removeRegressionDB",
"(",
"dbPath",
"string",
")",
"error",
"{",
"// Don't do anything if not in regression test mode.",
"if",
"!",
"cfg",
".",
"RegressionTest",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// Remove the old regression test database if it already exists... | // removeRegressionDB removes the existing regression test database if running
// in regression test mode and it already exists. | [
"removeRegressionDB",
"removes",
"the",
"existing",
"regression",
"test",
"database",
"if",
"running",
"in",
"regression",
"test",
"mode",
"and",
"it",
"already",
"exists",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/btcd.go#L176-L200 |
163,678 | btcsuite/btcd | btcd.go | blockDbPath | func blockDbPath(dbType string) string {
// The database name is based on the database type.
dbName := blockDbNamePrefix + "_" + dbType
if dbType == "sqlite" {
dbName = dbName + ".db"
}
dbPath := filepath.Join(cfg.DataDir, dbName)
return dbPath
} | go | func blockDbPath(dbType string) string {
// The database name is based on the database type.
dbName := blockDbNamePrefix + "_" + dbType
if dbType == "sqlite" {
dbName = dbName + ".db"
}
dbPath := filepath.Join(cfg.DataDir, dbName)
return dbPath
} | [
"func",
"blockDbPath",
"(",
"dbType",
"string",
")",
"string",
"{",
"// The database name is based on the database type.",
"dbName",
":=",
"blockDbNamePrefix",
"+",
"\"",
"\"",
"+",
"dbType",
"\n",
"if",
"dbType",
"==",
"\"",
"\"",
"{",
"dbName",
"=",
"dbName",
... | // dbPath returns the path to the block database given a database type. | [
"dbPath",
"returns",
"the",
"path",
"to",
"the",
"block",
"database",
"given",
"a",
"database",
"type",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/btcd.go#L203-L211 |
163,679 | btcsuite/btcd | btcd.go | warnMultipleDBs | func warnMultipleDBs() {
// This is intentionally not using the known db types which depend
// on the database types compiled into the binary since we want to
// detect legacy db types as well.
dbTypes := []string{"ffldb", "leveldb", "sqlite"}
duplicateDbPaths := make([]string, 0, len(dbTypes)-1)
for _, dbType :=... | go | func warnMultipleDBs() {
// This is intentionally not using the known db types which depend
// on the database types compiled into the binary since we want to
// detect legacy db types as well.
dbTypes := []string{"ffldb", "leveldb", "sqlite"}
duplicateDbPaths := make([]string, 0, len(dbTypes)-1)
for _, dbType :=... | [
"func",
"warnMultipleDBs",
"(",
")",
"{",
"// This is intentionally not using the known db types which depend",
"// on the database types compiled into the binary since we want to",
"// detect legacy db types as well.",
"dbTypes",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"... | // warnMultipleDBs shows a warning if multiple block database types are detected.
// This is not a situation most users want. It is handy for development however
// to support multiple side-by-side databases. | [
"warnMultipleDBs",
"shows",
"a",
"warning",
"if",
"multiple",
"block",
"database",
"types",
"are",
"detected",
".",
"This",
"is",
"not",
"a",
"situation",
"most",
"users",
"want",
".",
"It",
"is",
"handy",
"for",
"development",
"however",
"to",
"support",
"m... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/btcd.go#L216-L244 |
163,680 | btcsuite/btcd | wire/msgversion.go | HasService | func (msg *MsgVersion) HasService(service ServiceFlag) bool {
return msg.Services&service == service
} | go | func (msg *MsgVersion) HasService(service ServiceFlag) bool {
return msg.Services&service == service
} | [
"func",
"(",
"msg",
"*",
"MsgVersion",
")",
"HasService",
"(",
"service",
"ServiceFlag",
")",
"bool",
"{",
"return",
"msg",
".",
"Services",
"&",
"service",
"==",
"service",
"\n",
"}"
] | // HasService returns whether the specified service is supported by the peer
// that generated the message. | [
"HasService",
"returns",
"whether",
"the",
"specified",
"service",
"is",
"supported",
"by",
"the",
"peer",
"that",
"generated",
"the",
"message",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/wire/msgversion.go#L62-L64 |
163,681 | btcsuite/btcd | wire/msgversion.go | NewMsgVersion | func NewMsgVersion(me *NetAddress, you *NetAddress, nonce uint64,
lastBlock int32) *MsgVersion {
// Limit the timestamp to one second precision since the protocol
// doesn't support better.
return &MsgVersion{
ProtocolVersion: int32(ProtocolVersion),
Services: 0,
Timestamp: time.Unix(time.Now().... | go | func NewMsgVersion(me *NetAddress, you *NetAddress, nonce uint64,
lastBlock int32) *MsgVersion {
// Limit the timestamp to one second precision since the protocol
// doesn't support better.
return &MsgVersion{
ProtocolVersion: int32(ProtocolVersion),
Services: 0,
Timestamp: time.Unix(time.Now().... | [
"func",
"NewMsgVersion",
"(",
"me",
"*",
"NetAddress",
",",
"you",
"*",
"NetAddress",
",",
"nonce",
"uint64",
",",
"lastBlock",
"int32",
")",
"*",
"MsgVersion",
"{",
"// Limit the timestamp to one second precision since the protocol",
"// doesn't support better.",
"return... | // NewMsgVersion returns a new bitcoin version message that conforms to the
// Message interface using the passed parameters and defaults for the remaining
// fields. | [
"NewMsgVersion",
"returns",
"a",
"new",
"bitcoin",
"version",
"message",
"that",
"conforms",
"to",
"the",
"Message",
"interface",
"using",
"the",
"passed",
"parameters",
"and",
"defaults",
"for",
"the",
"remaining",
"fields",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/wire/msgversion.go#L223-L239 |
163,682 | btcsuite/btcd | wire/msgversion.go | validateUserAgent | func validateUserAgent(userAgent string) error {
if len(userAgent) > MaxUserAgentLen {
str := fmt.Sprintf("user agent too long [len %v, max %v]",
len(userAgent), MaxUserAgentLen)
return messageError("MsgVersion", str)
}
return nil
} | go | func validateUserAgent(userAgent string) error {
if len(userAgent) > MaxUserAgentLen {
str := fmt.Sprintf("user agent too long [len %v, max %v]",
len(userAgent), MaxUserAgentLen)
return messageError("MsgVersion", str)
}
return nil
} | [
"func",
"validateUserAgent",
"(",
"userAgent",
"string",
")",
"error",
"{",
"if",
"len",
"(",
"userAgent",
")",
">",
"MaxUserAgentLen",
"{",
"str",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"len",
"(",
"userAgent",
")",
",",
"MaxUserAgentLen",
"... | // validateUserAgent checks userAgent length against MaxUserAgentLen | [
"validateUserAgent",
"checks",
"userAgent",
"length",
"against",
"MaxUserAgentLen"
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/wire/msgversion.go#L242-L249 |
163,683 | btcsuite/btcd | upgrade.go | dirEmpty | func dirEmpty(dirPath string) (bool, error) {
f, err := os.Open(dirPath)
if err != nil {
return false, err
}
defer f.Close()
// Read the names of a max of one entry from the directory. When the
// directory is empty, an io.EOF error will be returned, so allow it.
names, err := f.Readdirnames(1)
if err != ni... | go | func dirEmpty(dirPath string) (bool, error) {
f, err := os.Open(dirPath)
if err != nil {
return false, err
}
defer f.Close()
// Read the names of a max of one entry from the directory. When the
// directory is empty, an io.EOF error will be returned, so allow it.
names, err := f.Readdirnames(1)
if err != ni... | [
"func",
"dirEmpty",
"(",
"dirPath",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"dirPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"defer",
... | // dirEmpty returns whether or not the specified directory path is empty. | [
"dirEmpty",
"returns",
"whether",
"or",
"not",
"the",
"specified",
"directory",
"path",
"is",
"empty",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/upgrade.go#L14-L29 |
163,684 | btcsuite/btcd | upgrade.go | oldBtcdHomeDir | func oldBtcdHomeDir() string {
// Search for Windows APPDATA first. This won't exist on POSIX OSes.
appData := os.Getenv("APPDATA")
if appData != "" {
return filepath.Join(appData, "btcd")
}
// Fall back to standard HOME directory that works for most POSIX OSes.
home := os.Getenv("HOME")
if home != "" {
re... | go | func oldBtcdHomeDir() string {
// Search for Windows APPDATA first. This won't exist on POSIX OSes.
appData := os.Getenv("APPDATA")
if appData != "" {
return filepath.Join(appData, "btcd")
}
// Fall back to standard HOME directory that works for most POSIX OSes.
home := os.Getenv("HOME")
if home != "" {
re... | [
"func",
"oldBtcdHomeDir",
"(",
")",
"string",
"{",
"// Search for Windows APPDATA first. This won't exist on POSIX OSes.",
"appData",
":=",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
"\n",
"if",
"appData",
"!=",
"\"",
"\"",
"{",
"return",
"filepath",
".",
"Join",... | // oldBtcdHomeDir returns the OS specific home directory btcd used prior to
// version 0.3.3. This has since been replaced with btcutil.AppDataDir, but
// this function is still provided for the automatic upgrade path. | [
"oldBtcdHomeDir",
"returns",
"the",
"OS",
"specific",
"home",
"directory",
"btcd",
"used",
"prior",
"to",
"version",
"0",
".",
"3",
".",
"3",
".",
"This",
"has",
"since",
"been",
"replaced",
"with",
"btcutil",
".",
"AppDataDir",
"but",
"this",
"function",
... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/upgrade.go#L34-L49 |
163,685 | btcsuite/btcd | upgrade.go | upgradeDBPathNet | func upgradeDBPathNet(oldDbPath, netName string) error {
// Prior to version 0.2.0, the database was named the same thing for
// both sqlite and leveldb. Use heuristics to figure out the type
// of the database and move it to the new path and name introduced with
// version 0.2.0 accordingly.
fi, err := os.Stat(o... | go | func upgradeDBPathNet(oldDbPath, netName string) error {
// Prior to version 0.2.0, the database was named the same thing for
// both sqlite and leveldb. Use heuristics to figure out the type
// of the database and move it to the new path and name introduced with
// version 0.2.0 accordingly.
fi, err := os.Stat(o... | [
"func",
"upgradeDBPathNet",
"(",
"oldDbPath",
",",
"netName",
"string",
")",
"error",
"{",
"// Prior to version 0.2.0, the database was named the same thing for",
"// both sqlite and leveldb. Use heuristics to figure out the type",
"// of the database and move it to the new path and name in... | // upgradeDBPathNet moves the database for a specific network from its
// location prior to btcd version 0.2.0 and uses heuristics to ascertain the old
// database type to rename to the new format. | [
"upgradeDBPathNet",
"moves",
"the",
"database",
"for",
"a",
"specific",
"network",
"from",
"its",
"location",
"prior",
"to",
"btcd",
"version",
"0",
".",
"2",
".",
"0",
"and",
"uses",
"heuristics",
"to",
"ascertain",
"the",
"old",
"database",
"type",
"to",
... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/upgrade.go#L54-L89 |
163,686 | btcsuite/btcd | upgrade.go | upgradeDBPaths | func upgradeDBPaths() error {
// Prior to version 0.2.0, the databases were in the "db" directory and
// their names were suffixed by "testnet" and "regtest" for their
// respective networks. Check for the old database and update it to the
// new path introduced with version 0.2.0 accordingly.
oldDbRoot := filepa... | go | func upgradeDBPaths() error {
// Prior to version 0.2.0, the databases were in the "db" directory and
// their names were suffixed by "testnet" and "regtest" for their
// respective networks. Check for the old database and update it to the
// new path introduced with version 0.2.0 accordingly.
oldDbRoot := filepa... | [
"func",
"upgradeDBPaths",
"(",
")",
"error",
"{",
"// Prior to version 0.2.0, the databases were in the \"db\" directory and",
"// their names were suffixed by \"testnet\" and \"regtest\" for their",
"// respective networks. Check for the old database and update it to the",
"// new path introduce... | // upgradeDBPaths moves the databases from their locations prior to btcd
// version 0.2.0 to their new locations. | [
"upgradeDBPaths",
"moves",
"the",
"databases",
"from",
"their",
"locations",
"prior",
"to",
"btcd",
"version",
"0",
".",
"2",
".",
"0",
"to",
"their",
"new",
"locations",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/upgrade.go#L93-L105 |
163,687 | btcsuite/btcd | upgrade.go | upgradeDataPaths | func upgradeDataPaths() error {
// No need to migrate if the old and new home paths are the same.
oldHomePath := oldBtcdHomeDir()
newHomePath := defaultHomeDir
if oldHomePath == newHomePath {
return nil
}
// Only migrate if the old path exists and the new one doesn't.
if fileExists(oldHomePath) && !fileExists... | go | func upgradeDataPaths() error {
// No need to migrate if the old and new home paths are the same.
oldHomePath := oldBtcdHomeDir()
newHomePath := defaultHomeDir
if oldHomePath == newHomePath {
return nil
}
// Only migrate if the old path exists and the new one doesn't.
if fileExists(oldHomePath) && !fileExists... | [
"func",
"upgradeDataPaths",
"(",
")",
"error",
"{",
"// No need to migrate if the old and new home paths are the same.",
"oldHomePath",
":=",
"oldBtcdHomeDir",
"(",
")",
"\n",
"newHomePath",
":=",
"defaultHomeDir",
"\n",
"if",
"oldHomePath",
"==",
"newHomePath",
"{",
"ret... | // upgradeDataPaths moves the application data from its location prior to btcd
// version 0.3.3 to its new location. | [
"upgradeDataPaths",
"moves",
"the",
"application",
"data",
"from",
"its",
"location",
"prior",
"to",
"btcd",
"version",
"0",
".",
"3",
".",
"3",
"to",
"its",
"new",
"location",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/upgrade.go#L109-L166 |
163,688 | btcsuite/btcd | btcjson/register.go | String | func (fl UsageFlag) String() string {
// No flags are set.
if fl == 0 {
return "0x0"
}
// Add individual bit flags.
s := ""
for flag := UFWalletOnly; flag < highestUsageFlagBit; flag <<= 1 {
if fl&flag == flag {
s += usageFlagStrings[flag] + "|"
fl -= flag
}
}
// Add remaining value as raw hex.
s... | go | func (fl UsageFlag) String() string {
// No flags are set.
if fl == 0 {
return "0x0"
}
// Add individual bit flags.
s := ""
for flag := UFWalletOnly; flag < highestUsageFlagBit; flag <<= 1 {
if fl&flag == flag {
s += usageFlagStrings[flag] + "|"
fl -= flag
}
}
// Add remaining value as raw hex.
s... | [
"func",
"(",
"fl",
"UsageFlag",
")",
"String",
"(",
")",
"string",
"{",
"// No flags are set.",
"if",
"fl",
"==",
"0",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"// Add individual bit flags.",
"s",
":=",
"\"",
"\"",
"\n",
"for",
"flag",
":=",
"UFWall... | // String returns the UsageFlag in human-readable form. | [
"String",
"returns",
"the",
"UsageFlag",
"in",
"human",
"-",
"readable",
"form",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/btcjson/register.go#L50-L72 |
163,689 | btcsuite/btcd | btcjson/register.go | baseKindString | func baseKindString(rt reflect.Type) string {
numIndirects := 0
for rt.Kind() == reflect.Ptr {
numIndirects++
rt = rt.Elem()
}
return fmt.Sprintf("%s%s", strings.Repeat("*", numIndirects), rt.Kind())
} | go | func baseKindString(rt reflect.Type) string {
numIndirects := 0
for rt.Kind() == reflect.Ptr {
numIndirects++
rt = rt.Elem()
}
return fmt.Sprintf("%s%s", strings.Repeat("*", numIndirects), rt.Kind())
} | [
"func",
"baseKindString",
"(",
"rt",
"reflect",
".",
"Type",
")",
"string",
"{",
"numIndirects",
":=",
"0",
"\n",
"for",
"rt",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Ptr",
"{",
"numIndirects",
"++",
"\n",
"rt",
"=",
"rt",
".",
"Elem",
"(",
"... | // baseKindString returns the base kind for a given reflect.Type after
// indirecting through all pointers. | [
"baseKindString",
"returns",
"the",
"base",
"kind",
"for",
"a",
"given",
"reflect",
".",
"Type",
"after",
"indirecting",
"through",
"all",
"pointers",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/btcjson/register.go#L95-L103 |
163,690 | btcsuite/btcd | btcjson/register.go | isAcceptableKind | func isAcceptableKind(kind reflect.Kind) bool {
switch kind {
case reflect.Chan:
fallthrough
case reflect.Complex64:
fallthrough
case reflect.Complex128:
fallthrough
case reflect.Func:
fallthrough
case reflect.Ptr:
fallthrough
case reflect.Interface:
return false
}
return true
} | go | func isAcceptableKind(kind reflect.Kind) bool {
switch kind {
case reflect.Chan:
fallthrough
case reflect.Complex64:
fallthrough
case reflect.Complex128:
fallthrough
case reflect.Func:
fallthrough
case reflect.Ptr:
fallthrough
case reflect.Interface:
return false
}
return true
} | [
"func",
"isAcceptableKind",
"(",
"kind",
"reflect",
".",
"Kind",
")",
"bool",
"{",
"switch",
"kind",
"{",
"case",
"reflect",
".",
"Chan",
":",
"fallthrough",
"\n",
"case",
"reflect",
".",
"Complex64",
":",
"fallthrough",
"\n",
"case",
"reflect",
".",
"Comp... | // isAcceptableKind returns whether or not the passed field type is a supported
// type. It is called after the first pointer indirection, so further pointers
// are not supported. | [
"isAcceptableKind",
"returns",
"whether",
"or",
"not",
"the",
"passed",
"field",
"type",
"is",
"a",
"supported",
"type",
".",
"It",
"is",
"called",
"after",
"the",
"first",
"pointer",
"indirection",
"so",
"further",
"pointers",
"are",
"not",
"supported",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/btcjson/register.go#L108-L125 |
163,691 | btcsuite/btcd | btcjson/register.go | MustRegisterCmd | func MustRegisterCmd(method string, cmd interface{}, flags UsageFlag) {
if err := RegisterCmd(method, cmd, flags); err != nil {
panic(fmt.Sprintf("failed to register type %q: %v\n", method,
err))
}
} | go | func MustRegisterCmd(method string, cmd interface{}, flags UsageFlag) {
if err := RegisterCmd(method, cmd, flags); err != nil {
panic(fmt.Sprintf("failed to register type %q: %v\n", method,
err))
}
} | [
"func",
"MustRegisterCmd",
"(",
"method",
"string",
",",
"cmd",
"interface",
"{",
"}",
",",
"flags",
"UsageFlag",
")",
"{",
"if",
"err",
":=",
"RegisterCmd",
"(",
"method",
",",
"cmd",
",",
"flags",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"f... | // MustRegisterCmd performs the same function as RegisterCmd except it panics
// if there is an error. This should only be called from package init
// functions. | [
"MustRegisterCmd",
"performs",
"the",
"same",
"function",
"as",
"RegisterCmd",
"except",
"it",
"panics",
"if",
"there",
"is",
"an",
"error",
".",
"This",
"should",
"only",
"be",
"called",
"from",
"package",
"init",
"functions",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/btcjson/register.go#L272-L277 |
163,692 | btcsuite/btcd | btcjson/register.go | RegisteredCmdMethods | func RegisteredCmdMethods() []string {
registerLock.Lock()
defer registerLock.Unlock()
methods := make([]string, 0, len(methodToInfo))
for k := range methodToInfo {
methods = append(methods, k)
}
sort.Sort(sort.StringSlice(methods))
return methods
} | go | func RegisteredCmdMethods() []string {
registerLock.Lock()
defer registerLock.Unlock()
methods := make([]string, 0, len(methodToInfo))
for k := range methodToInfo {
methods = append(methods, k)
}
sort.Sort(sort.StringSlice(methods))
return methods
} | [
"func",
"RegisteredCmdMethods",
"(",
")",
"[",
"]",
"string",
"{",
"registerLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"registerLock",
".",
"Unlock",
"(",
")",
"\n\n",
"methods",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"me... | // RegisteredCmdMethods returns a sorted list of methods for all registered
// commands. | [
"RegisteredCmdMethods",
"returns",
"a",
"sorted",
"list",
"of",
"methods",
"for",
"all",
"registered",
"commands",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/btcjson/register.go#L281-L292 |
163,693 | btcsuite/btcd | rpcclient/mining.go | Receive | func (r FutureGenerateResult) Receive() ([]*chainhash.Hash, error) {
res, err := receiveFuture(r)
if err != nil {
return nil, err
}
// Unmarshal result as a list of strings.
var result []string
err = json.Unmarshal(res, &result)
if err != nil {
return nil, err
}
// Convert each block hash to a chainhash.... | go | func (r FutureGenerateResult) Receive() ([]*chainhash.Hash, error) {
res, err := receiveFuture(r)
if err != nil {
return nil, err
}
// Unmarshal result as a list of strings.
var result []string
err = json.Unmarshal(res, &result)
if err != nil {
return nil, err
}
// Convert each block hash to a chainhash.... | [
"func",
"(",
"r",
"FutureGenerateResult",
")",
"Receive",
"(",
")",
"(",
"[",
"]",
"*",
"chainhash",
".",
"Hash",
",",
"error",
")",
"{",
"res",
",",
"err",
":=",
"receiveFuture",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",... | // Receive waits for the response promised by the future and returns a list of
// block hashes generated by the call. | [
"Receive",
"waits",
"for",
"the",
"response",
"promised",
"by",
"the",
"future",
"and",
"returns",
"a",
"list",
"of",
"block",
"hashes",
"generated",
"by",
"the",
"call",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/mining.go#L23-L47 |
163,694 | btcsuite/btcd | rpcclient/mining.go | GenerateAsync | func (c *Client) GenerateAsync(numBlocks uint32) FutureGenerateResult {
cmd := btcjson.NewGenerateCmd(numBlocks)
return c.sendCmd(cmd)
} | go | func (c *Client) GenerateAsync(numBlocks uint32) FutureGenerateResult {
cmd := btcjson.NewGenerateCmd(numBlocks)
return c.sendCmd(cmd)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GenerateAsync",
"(",
"numBlocks",
"uint32",
")",
"FutureGenerateResult",
"{",
"cmd",
":=",
"btcjson",
".",
"NewGenerateCmd",
"(",
"numBlocks",
")",
"\n",
"return",
"c",
".",
"sendCmd",
"(",
"cmd",
")",
"\n",
"}"
] | // GenerateAsync returns an instance of a type that can be used to get
// the result of the RPC at some future time by invoking the Receive function on
// the returned instance.
//
// See Generate for the blocking version and more details. | [
"GenerateAsync",
"returns",
"an",
"instance",
"of",
"a",
"type",
"that",
"can",
"be",
"used",
"to",
"get",
"the",
"result",
"of",
"the",
"RPC",
"at",
"some",
"future",
"time",
"by",
"invoking",
"the",
"Receive",
"function",
"on",
"the",
"returned",
"instan... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/mining.go#L54-L57 |
163,695 | btcsuite/btcd | rpcclient/mining.go | Generate | func (c *Client) Generate(numBlocks uint32) ([]*chainhash.Hash, error) {
return c.GenerateAsync(numBlocks).Receive()
} | go | func (c *Client) Generate(numBlocks uint32) ([]*chainhash.Hash, error) {
return c.GenerateAsync(numBlocks).Receive()
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Generate",
"(",
"numBlocks",
"uint32",
")",
"(",
"[",
"]",
"*",
"chainhash",
".",
"Hash",
",",
"error",
")",
"{",
"return",
"c",
".",
"GenerateAsync",
"(",
"numBlocks",
")",
".",
"Receive",
"(",
")",
"\n",
"}"... | // Generate generates numBlocks blocks and returns their hashes. | [
"Generate",
"generates",
"numBlocks",
"blocks",
"and",
"returns",
"their",
"hashes",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/mining.go#L60-L62 |
163,696 | btcsuite/btcd | rpcclient/mining.go | Receive | func (r FutureGetGenerateResult) Receive() (bool, error) {
res, err := receiveFuture(r)
if err != nil {
return false, err
}
// Unmarshal result as a boolean.
var result bool
err = json.Unmarshal(res, &result)
if err != nil {
return false, err
}
return result, nil
} | go | func (r FutureGetGenerateResult) Receive() (bool, error) {
res, err := receiveFuture(r)
if err != nil {
return false, err
}
// Unmarshal result as a boolean.
var result bool
err = json.Unmarshal(res, &result)
if err != nil {
return false, err
}
return result, nil
} | [
"func",
"(",
"r",
"FutureGetGenerateResult",
")",
"Receive",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"res",
",",
"err",
":=",
"receiveFuture",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n\... | // Receive waits for the response promised by the future and returns true if the
// server is set to mine, otherwise false. | [
"Receive",
"waits",
"for",
"the",
"response",
"promised",
"by",
"the",
"future",
"and",
"returns",
"true",
"if",
"the",
"server",
"is",
"set",
"to",
"mine",
"otherwise",
"false",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/mining.go#L70-L84 |
163,697 | btcsuite/btcd | rpcclient/mining.go | GetGenerateAsync | func (c *Client) GetGenerateAsync() FutureGetGenerateResult {
cmd := btcjson.NewGetGenerateCmd()
return c.sendCmd(cmd)
} | go | func (c *Client) GetGenerateAsync() FutureGetGenerateResult {
cmd := btcjson.NewGetGenerateCmd()
return c.sendCmd(cmd)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetGenerateAsync",
"(",
")",
"FutureGetGenerateResult",
"{",
"cmd",
":=",
"btcjson",
".",
"NewGetGenerateCmd",
"(",
")",
"\n",
"return",
"c",
".",
"sendCmd",
"(",
"cmd",
")",
"\n",
"}"
] | // GetGenerateAsync returns an instance of a type that can be used to get
// the result of the RPC at some future time by invoking the Receive function on
// the returned instance.
//
// See GetGenerate for the blocking version and more details. | [
"GetGenerateAsync",
"returns",
"an",
"instance",
"of",
"a",
"type",
"that",
"can",
"be",
"used",
"to",
"get",
"the",
"result",
"of",
"the",
"RPC",
"at",
"some",
"future",
"time",
"by",
"invoking",
"the",
"Receive",
"function",
"on",
"the",
"returned",
"ins... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/mining.go#L91-L94 |
163,698 | btcsuite/btcd | rpcclient/mining.go | SetGenerateAsync | func (c *Client) SetGenerateAsync(enable bool, numCPUs int) FutureSetGenerateResult {
cmd := btcjson.NewSetGenerateCmd(enable, &numCPUs)
return c.sendCmd(cmd)
} | go | func (c *Client) SetGenerateAsync(enable bool, numCPUs int) FutureSetGenerateResult {
cmd := btcjson.NewSetGenerateCmd(enable, &numCPUs)
return c.sendCmd(cmd)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"SetGenerateAsync",
"(",
"enable",
"bool",
",",
"numCPUs",
"int",
")",
"FutureSetGenerateResult",
"{",
"cmd",
":=",
"btcjson",
".",
"NewSetGenerateCmd",
"(",
"enable",
",",
"&",
"numCPUs",
")",
"\n",
"return",
"c",
"."... | // SetGenerateAsync returns an instance of a type that can be used to get the
// result of the RPC at some future time by invoking the Receive function on the
// returned instance.
//
// See SetGenerate for the blocking version and more details. | [
"SetGenerateAsync",
"returns",
"an",
"instance",
"of",
"a",
"type",
"that",
"can",
"be",
"used",
"to",
"get",
"the",
"result",
"of",
"the",
"RPC",
"at",
"some",
"future",
"time",
"by",
"invoking",
"the",
"Receive",
"function",
"on",
"the",
"returned",
"ins... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/mining.go#L117-L120 |
163,699 | btcsuite/btcd | rpcclient/mining.go | GetHashesPerSecAsync | func (c *Client) GetHashesPerSecAsync() FutureGetHashesPerSecResult {
cmd := btcjson.NewGetHashesPerSecCmd()
return c.sendCmd(cmd)
} | go | func (c *Client) GetHashesPerSecAsync() FutureGetHashesPerSecResult {
cmd := btcjson.NewGetHashesPerSecCmd()
return c.sendCmd(cmd)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetHashesPerSecAsync",
"(",
")",
"FutureGetHashesPerSecResult",
"{",
"cmd",
":=",
"btcjson",
".",
"NewGetHashesPerSecCmd",
"(",
")",
"\n",
"return",
"c",
".",
"sendCmd",
"(",
"cmd",
")",
"\n",
"}"
] | // GetHashesPerSecAsync returns an instance of a type that can be used to get
// the result of the RPC at some future time by invoking the Receive function on
// the returned instance.
//
// See GetHashesPerSec for the blocking version and more details. | [
"GetHashesPerSecAsync",
"returns",
"an",
"instance",
"of",
"a",
"type",
"that",
"can",
"be",
"used",
"to",
"get",
"the",
"result",
"of",
"the",
"RPC",
"at",
"some",
"future",
"time",
"by",
"invoking",
"the",
"Receive",
"function",
"on",
"the",
"returned",
... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/mining.go#L155-L158 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.