Skip to content

Commit 750c5a5

Browse files
committed
Merge #10189: devtools/net: add a verifier for scriptable changes. Use it to make CNode::id private.
0f3471f net: make CNode's id private (Cory Fields) 9ff0a51 scripted-diff: net: Use accessor rather than node's id directly (Cory Fields) e50c33e devtools: add script to verify scriptable changes (Cory Fields) Tree-SHA512: a0ff50f4e1d38a2b63109b4996546c91b3e02e00d92c0bf04f48792948f78b1f6d9227a15d25c823fd4723a0277fc6a32c2c1287c7abbb7e50fd82ffb0f8d994
2 parents 170bc2c + 0f3471f commit 750c5a5

File tree

5 files changed

+97
-57
lines changed

5 files changed

+97
-57
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ install:
4343
- if [ -n "$PACKAGES" ]; then travis_retry sudo apt-get update; fi
4444
- if [ -n "$PACKAGES" ]; then travis_retry sudo apt-get install --no-install-recommends --no-upgrade -qq $PACKAGES; fi
4545
before_script:
46+
- if [ "$TRAVIS_EVENT_TYPE" = "pull_request" ]; then contrib/devtools/commit-script-check.sh $TRAVIS_COMMIT_RANGE; fi
4647
- unset CC; unset CXX
4748
- if [ "$CHECK_DOC" = 1 ]; then contrib/devtools/check-doc.py; fi
4849
- mkdir -p depends/SDKs depends/sdk-sources
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/sh
2+
# Copyright (c) 2017 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
6+
# This simple script checks for commits beginning with: scripted-diff:
7+
# If found, looks for a script between the lines -BEGIN VERIFY SCRIPT- and
8+
# -END VERIFY SCRIPT-. If no ending is found, it reads until the end of the
9+
# commit message.
10+
11+
# The resulting script should exactly transform the previous commit into the current
12+
# one. Any remaining diff signals an error.
13+
14+
if test "x$1" = "x"; then
15+
echo "Usage: $0 <commit>..."
16+
exit 1
17+
fi
18+
19+
RET=0
20+
PREV_BRANCH=`git name-rev --name-only HEAD`
21+
PREV_HEAD=`git rev-parse HEAD`
22+
for i in `git rev-list --reverse $1`; do
23+
git rev-list -n 1 --pretty="%s" $i | grep -q "^scripted-diff:" || continue
24+
git checkout --quiet $i^ || exit
25+
SCRIPT="`git rev-list --format=%b -n1 $i | sed '/^-BEGIN VERIFY SCRIPT-$/,/^-END VERIFY SCRIPT-$/{//!b};d'`"
26+
if test "x$SCRIPT" = "x"; then
27+
echo "Error: missing script for: $i"
28+
echo "Failed"
29+
RET=1
30+
else
31+
echo "Running script for: $i"
32+
echo "$SCRIPT"
33+
eval "$SCRIPT"
34+
git --no-pager diff --exit-code $i && echo "OK" || (echo "Failed"; false) || RET=1
35+
fi
36+
git reset --quiet --hard HEAD
37+
done
38+
git checkout --quiet $PREV_BRANCH 2>/dev/null || git checkout --quiet $PREV_HEAD
39+
exit $RET

src/net.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ bool CConnman::AttemptToEvictConnection()
948948
continue;
949949
if (node->fDisconnect)
950950
continue;
951-
NodeEvictionCandidate candidate = {node->id, node->nTimeConnected, node->nMinPingUsecTime,
951+
NodeEvictionCandidate candidate = {node->GetId(), node->nTimeConnected, node->nMinPingUsecTime,
952952
node->nLastBlockTime, node->nLastTXTime,
953953
(node->nServices & nRelevantServices) == nRelevantServices,
954954
node->fRelayTxes, node->pfilter != NULL, node->addr, node->nKeyedNetGroup};
@@ -1374,7 +1374,7 @@ void CConnman::ThreadSocketHandler()
13741374
{
13751375
if (pnode->nLastRecv == 0 || pnode->nLastSend == 0)
13761376
{
1377-
LogPrint(BCLog::NET, "socket no message in first 60 seconds, %d %d from %d\n", pnode->nLastRecv != 0, pnode->nLastSend != 0, pnode->id);
1377+
LogPrint(BCLog::NET, "socket no message in first 60 seconds, %d %d from %d\n", pnode->nLastRecv != 0, pnode->nLastSend != 0, pnode->GetId());
13781378
pnode->fDisconnect = true;
13791379
}
13801380
else if (nTime - pnode->nLastSend > TIMEOUT_INTERVAL)
@@ -1394,7 +1394,7 @@ void CConnman::ThreadSocketHandler()
13941394
}
13951395
else if (!pnode->fSuccessfullyConnected)
13961396
{
1397-
LogPrintf("version handshake timeout from %d\n", pnode->id);
1397+
LogPrintf("version handshake timeout from %d\n", pnode->GetId());
13981398
pnode->fDisconnect = true;
13991399
}
14001400
}
@@ -2487,7 +2487,7 @@ bool CConnman::DisconnectNode(NodeId id)
24872487
{
24882488
LOCK(cs_vNodes);
24892489
for(CNode* pnode : vNodes) {
2490-
if (id == pnode->id) {
2490+
if (id == pnode->GetId()) {
24912491
pnode->fDisconnect = true;
24922492
return true;
24932493
}
@@ -2625,10 +2625,10 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
26252625
nTimeConnected(GetSystemTimeInSeconds()),
26262626
addr(addrIn),
26272627
fInbound(fInboundIn),
2628-
id(idIn),
26292628
nKeyedNetGroup(nKeyedNetGroupIn),
26302629
addrKnown(5000, 0.001),
26312630
filterInventoryKnown(50000, 0.000001),
2631+
id(idIn),
26322632
nLocalHostNonce(nLocalHostNonceIn),
26332633
nLocalServices(nLocalServicesIn),
26342634
nMyStartingHeight(nMyStartingHeightIn),
@@ -2744,7 +2744,7 @@ void CConnman::PushMessage(CNode* pnode, CSerializedNetMsg&& msg)
27442744
{
27452745
size_t nMessageSize = msg.data.size();
27462746
size_t nTotalSize = nMessageSize + CMessageHeader::HEADER_SIZE;
2747-
LogPrint(BCLog::NET, "sending %s (%d bytes) peer=%d\n", SanitizeString(msg.command.c_str()), nMessageSize, pnode->id);
2747+
LogPrint(BCLog::NET, "sending %s (%d bytes) peer=%d\n", SanitizeString(msg.command.c_str()), nMessageSize, pnode->GetId());
27482748

27492749
std::vector<unsigned char> serializedHeader;
27502750
serializedHeader.reserve(CMessageHeader::HEADER_SIZE);
@@ -2782,7 +2782,7 @@ bool CConnman::ForNode(NodeId id, std::function<bool(CNode* pnode)> func)
27822782
CNode* found = nullptr;
27832783
LOCK(cs_vNodes);
27842784
for (auto&& pnode : vNodes) {
2785-
if(pnode->id == id) {
2785+
if(pnode->GetId() == id) {
27862786
found = pnode;
27872787
break;
27882788
}

src/net.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,6 @@ class CNode
611611
CCriticalSection cs_filter;
612612
CBloomFilter* pfilter;
613613
std::atomic<int> nRefCount;
614-
const NodeId id;
615614

616615
const uint64_t nKeyedNetGroup;
617616
std::atomic_bool fPauseRecv;
@@ -682,6 +681,7 @@ class CNode
682681
private:
683682
CNode(const CNode&);
684683
void operator=(const CNode&);
684+
const NodeId id;
685685

686686

687687
const uint64_t nLocalHostNonce;

0 commit comments

Comments
 (0)