Skip to content

Commit

Permalink
Not connecting to peers from peers
Browse files Browse the repository at this point in the history
  • Loading branch information
SDCDev committed May 5, 2015
1 parent 7575f88 commit 5b95332
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 17 deletions.
2 changes: 1 addition & 1 deletion shadow.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
TEMPLATE = app
TARGET = shadow
VERSION = 1.3.2.2
VERSION = 1.3.2.3
INCLUDEPATH += src src/json src/qt
DEFINES += BOOST_THREAD_USE_LIB BOOST_SPIRIT_THREADSAFE
CONFIG += no_include_pwd
Expand Down
2 changes: 1 addition & 1 deletion src/clientversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define CLIENT_VERSION_MAJOR 1
#define CLIENT_VERSION_MINOR 3
#define CLIENT_VERSION_REVISION 2
#define CLIENT_VERSION_BUILD 2
#define CLIENT_VERSION_BUILD 3

// Converts the parameter X to a string after macro replacement on X has been performed.
// Don't merge these into one macro!
Expand Down
5 changes: 4 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4974,8 +4974,11 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,

// record my external IP reported by peer
if (addrFrom.IsRoutable() && addrMe.IsRoutable())
{
addrSeenByPeer = addrMe;

AddLocal(addrSeenByPeer, LOCAL_BIND);
};

// Be shy and don't send version until we hear
if (pfrom->fInbound)
pfrom->PushVersion();
Expand Down
20 changes: 12 additions & 8 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,14 @@ static const int MAX_OUTBOUND_CONNECTIONS = 16;

bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant *grantOutbound = NULL, const char *strDest = NULL, bool fOneShot = false);


struct LocalServiceInfo {
int nScore;
int nPort;
};

//
// Global state variables
//
bool fDiscover = true;
bool fUseUPnP = false;

static CCriticalSection cs_mapLocalHost;
static map<CNetAddr, LocalServiceInfo> mapLocalHost;
CCriticalSection cs_mapLocalHost;
map<CNetAddr, LocalServiceInfo> mapLocalHost;
static bool vfReachable[NET_MAX] = {};
static bool vfLimited[NET_MAX] = {};
static CNode* pnodeLocalHost = NULL;
Expand Down Expand Up @@ -330,6 +324,13 @@ bool IsLocal(const CService& addr)
return mapLocalHost.count(addr) > 0;
}

/** check whether a given network is one we can probably connect to */
bool IsReachable(enum Network net)
{
LOCK(cs_mapLocalHost);
return vfReachable[net] && !vfLimited[net];
}

/** check whether a given address is in a network we can probably connect to */
bool IsReachable(const CNetAddr& addr)
{
Expand Down Expand Up @@ -1244,8 +1245,11 @@ void ThreadDNSAddressSeed()
{
BOOST_FOREACH(CNetAddr& ip, vIPs)
{

int nOneDay = 24*3600;
CAddress addr = CAddress(CService(ip, Params().GetDefaultPort()));
SetReachable(addr.GetNetwork());

addr.nTime = GetTime() - 3*nOneDay - GetRand(4*nOneDay); // use a random age between 3 and 7 days old
vAdd.push_back(addr);
found++;
Expand Down
9 changes: 9 additions & 0 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ bool AddLocal(const CNetAddr& addr, int nScore = LOCAL_NONE);
bool SeenLocal(const CService& addr);
bool IsLocal(const CService& addr);
bool GetLocal(CService &addr, const CNetAddr *paddrPeer = NULL);
bool IsReachable(enum Network net);
bool IsReachable(const CNetAddr &addr);
void SetReachable(enum Network net, bool fFlag = true);
CAddress GetLocalAddress(const CNetAddr *paddrPeer = NULL);
Expand Down Expand Up @@ -145,6 +146,14 @@ extern std::map<CInv, int64_t> mapAlreadyAskedFor;
extern std::vector<std::string> vAddedNodes;
extern CCriticalSection cs_vAddedNodes;

struct LocalServiceInfo {
int nScore;
int nPort;
};

extern CCriticalSection cs_mapLocalHost;
extern std::map<CNetAddr, LocalServiceInfo> mapLocalHost;


class CNodeStateStats
{
Expand Down
5 changes: 3 additions & 2 deletions src/qt/messagemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "ui_interface.h"
#include "base58.h"
#include "json_spirit.h"
#include "init.h"

#include <QSet>
#include <QTimer>
Expand Down Expand Up @@ -54,7 +55,7 @@ class MessageTablePriv
};

{
LOCK(cs_smsgDB);
LOCK2(pwalletMain->cs_wallet, cs_smsgDB);

SecMsgDB dbSmsg;

Expand Down Expand Up @@ -523,7 +524,7 @@ int MessageModel::lookupMessage(const QString &key) const

static void NotifySecMsgInbox(MessageModel *messageModel, SecMsgStored inboxHdr)
{
// Too noisy: OutputDebugStringF("NotifySecMsgInboxChanged %s\n", message);
// Too noisy: LogPrintf("NotifySecMsgInboxChanged %s\n", message);
QMetaObject::invokeMethod(messageModel, "newMessage", Qt::QueuedConnection,
Q_ARG(SecMsgStored, inboxHdr));
}
Expand Down
86 changes: 86 additions & 0 deletions src/rpcnet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,89 @@ Value sendalert(const Array& params, bool fHelp)
result.push_back(Pair("nCancel", alert.nCancel));
return result;
}


static Array GetNetworksInfo()
{
Array networks;
for(int n=0; n<NET_MAX; ++n)
{
enum Network network = static_cast<enum Network>(n);
if(network == NET_UNROUTABLE)
continue;
proxyType proxy;
Object obj;
GetProxy(network, proxy);
obj.push_back(Pair("name", GetNetworkName(network)));
obj.push_back(Pair("limited", IsLimited(network)));
obj.push_back(Pair("reachable", IsReachable(network)));
obj.push_back(Pair("proxy", proxy.IsValid() ? proxy.ToStringIPPort() : std::string()));
networks.push_back(obj);
}
return networks;
}

Value getnetworkinfo(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 0)
throw std::runtime_error(
"getnetworkinfo\n"
"Returns an object containing various state info regarding P2P networking.\n"
"\nResult:\n"
"{\n"
" \"version\": xxxxx, (numeric) the server version\n"
" \"subversion\": \"/Satoshi:x.x.x/\", (string) the server subversion string\n"
" \"protocolversion\": xxxxx, (numeric) the protocol version\n"
" \"localservices\": \"xxxxxxxxxxxxxxxx\", (string) the services we offer to the network\n"
" \"timeoffset\": xxxxx, (numeric) the time offset\n"
" \"connections\": xxxxx, (numeric) the number of connections\n"
" \"networks\": [ (array) information per network\n"
" {\n"
" \"name\": \"xxx\", (string) network (ipv4, ipv6 or onion)\n"
" \"limited\": true|false, (boolean) is the network limited using -onlynet?\n"
" \"reachable\": true|false, (boolean) is the network reachable?\n"
" \"proxy\": \"host:port\" (string) the proxy that is used for this network, or empty if none\n"
" }\n"
" ,...\n"
" ],\n"
" \"relayfee\": x.xxxxxxxx, (numeric) minimum relay fee for non-free transactions in sdc/kb\n"
" \"localaddresses\": [ (array) list of local addresses\n"
" {\n"
" \"address\": \"xxxx\", (string) network address\n"
" \"port\": xxx, (numeric) network port\n"
" \"score\": xxx (numeric) relative score\n"
" }\n"
" ,...\n"
" ]\n"
"}\n"
);

LOCK(cs_main);

Object obj;
obj.push_back(Pair("version", CLIENT_VERSION));
obj.push_back(Pair("subversion",
FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, std::vector<std::string>())));
obj.push_back(Pair("protocolversion",PROTOCOL_VERSION));
obj.push_back(Pair("localservices", strprintf("%016x", nLocalServices)));
obj.push_back(Pair("timeoffset", GetTimeOffset()));
obj.push_back(Pair("connections", (int)vNodes.size()));
obj.push_back(Pair("networks", GetNetworksInfo()));
//obj.push_back(Pair("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK())));
Array localAddresses;
{
LOCK(cs_mapLocalHost);
BOOST_FOREACH(const PAIRTYPE(CNetAddr, LocalServiceInfo) &item, mapLocalHost)
{
Object rec;
rec.push_back(Pair("address", item.first.ToString()));
rec.push_back(Pair("port", item.second.nPort));
rec.push_back(Pair("score", item.second.nScore));
localAddresses.push_back(rec);
}
}
obj.push_back(Pair("localaddresses", localAddresses));
return obj;
}


3 changes: 3 additions & 0 deletions src/rpcserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,10 @@ static const CRPCCommand vRPCCommands[] =
{ "repairwallet", &repairwallet, false, true, false },
{ "resendtx", &resendtx, false, true, false },
{ "makekeypair", &makekeypair, false, true, false },

{ "sendalert", &sendalert, false, false, false },
{ "getnetworkinfo", &getnetworkinfo, false, false, false },


{ "getnewstealthaddress", &getnewstealthaddress, false, false, false },
{ "liststealthaddresses", &liststealthaddresses, false, false, false },
Expand Down
1 change: 1 addition & 0 deletions src/rpcserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ extern json_spirit::Value dumpprivkey(const json_spirit::Array& params, bool fHe
extern json_spirit::Value importprivkey(const json_spirit::Array& params, bool fHelp);

extern json_spirit::Value sendalert(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getnetworkinfo(const json_spirit::Array& params, bool fHelp);

extern json_spirit::Value getsubsidy(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getmininginfo(const json_spirit::Array& params, bool fHelp);
Expand Down
12 changes: 8 additions & 4 deletions src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5164,11 +5164,15 @@ int CWallet::CountOwnedAnonOutputs(std::map<int64_t, int>& mOwnedOutputCounts, b
//LogPrintf("[rem] mi->second.GetDepthInMainChain() %d \n", mi->second.GetDepthInMainChain());
//LogPrintf("[rem] mi->second.hashBlock %s \n", mi->second.hashBlock.ToString().c_str());
// -- txn must be in MIN_ANON_SPEND_DEPTH deep in the blockchain to be spent
if (fMatureOnly
&& mi->second.GetDepthInMainChain() < MIN_ANON_SPEND_DEPTH)

{
continue;
};
LOCK(cs_main);
if (fMatureOnly
&& mi->second.GetDepthInMainChain() < MIN_ANON_SPEND_DEPTH)
{
continue;
};
}

// TODO: check ReadAnonOutput?

Expand Down

0 comments on commit 5b95332

Please sign in to comment.