Skip to content

Commit

Permalink
Adding I2P code. Still some more to do before it's ready.
Browse files Browse the repository at this point in the history
  • Loading branch information
meeh420 committed Jun 8, 2013
1 parent 9e2b90f commit dc00622
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 1 deletion.
File renamed without changes.
4 changes: 4 additions & 0 deletions src/addrman.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@ class CAddrInfo : public CAddress
#define ADDRMAN_MIN_FAIL_DAYS 7

// the maximum percentage of nodes to return in a getaddr call
#ifdef USE_NATIVE_I2P
#define ADDRMAN_GETADDR_MAX_PCT 100
#else
#define ADDRMAN_GETADDR_MAX_PCT 23
#endif

// the maximum number of nodes to return in a getaddr call
#define ADDRMAN_GETADDR_MAX 2500
Expand Down
26 changes: 26 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#include <signal.h>
#endif

#ifdef USE_NATIVE_I2P
#include "i2p.h"
#endif

using namespace std;
using namespace boost;

Expand Down Expand Up @@ -200,6 +204,13 @@ bool static InitWarning(const std::string &str)
return true;
}

#ifdef USE_NATIVE_I2P
bool static BindNativeI2P(/*bool fError = true*/) {
if (IsLimited(NET_NATIVE_I2P))
return false;
return BindListenNativeI2P();
}
#endif

bool static Bind(const CService &addr, bool fError = true) {
if (IsLimited(addr))
Expand All @@ -213,6 +224,7 @@ bool static Bind(const CService &addr, bool fError = true) {
return true;
}


// Core-specific options shared between UI and daemon
std::string HelpMessage()
{
Expand Down Expand Up @@ -330,6 +342,16 @@ bool AppInit2()

// ********************************************************* Step 2: parameter interactions

#ifdef USE_NATIVE_I2P
if (GetBoolArg(I2P_SAM_GENERATE_DESTINATION_PARAM)) {
const std::pair<const std::string, const std::string> generatedDest = I2PSession::Instance().destGenerate();
const std::string& pub = generatedDest.first;
const std::string& priv = generatedDest.second;
uiInterface.ThreadSafeShowGeneratedI2PAddress("Anoncoin I2P", pub, priv, I2PSession::GenerateB32AddressFromDestination(pub), GetConfigFile().string());
return false;
}
#endif

fTestNet = GetBoolArg("-testnet");
// Anoncoin: Keep irc seeding on by default for now.
// if (fTestNet)
Expand Down Expand Up @@ -552,6 +574,10 @@ bool AppInit2()
#endif
if (!IsLimited(NET_IPV4))
fBound |= Bind(CService(inaddr_any, GetListenPort()), !fBound);
#ifdef USE_NATIVE_I2P
if (!IsLimited(NET_NATIVE_I2P))
fBound |= BindNativeI2P();
#endif
}
if (!fBound)
return InitError(_("Failed to listen on any port. Use -listen=0 if you want this."));
Expand Down
12 changes: 12 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2448,6 +2448,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
// Change version
pfrom->PushMessage("verack");
pfrom->vSend.SetVersion(min(pfrom->nVersion, PROTOCOL_VERSION));
#ifdef USE_NATIVE_I2P
if (pfrom->nServices & NODE_I2P)
pfrom->vSend.SetType(pfrom->vSend.GetType() & ~SER_IPADDRONLY);
else
pfrom->vSend.SetType(pfrom->vSend.GetType() & SER_IPADDRONLY);
#endif

if (!pfrom->fInbound)
{
Expand Down Expand Up @@ -2511,6 +2517,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
else if (strCommand == "verack")
{
pfrom->vRecv.SetVersion(min(pfrom->nVersion, PROTOCOL_VERSION));
#ifdef USE_NATIVE_I2P
if (pfrom->nServices & NODE_I2P)
pfrom->vRecv.SetType(pfrom->vRecv.GetType() & ~SER_IPADDRONLY);
else
pfrom->vRecv.SetType(pfrom->vRecv.GetType() & SER_IPADDRONLY);
#endif
}


Expand Down
21 changes: 21 additions & 0 deletions src/makefile.mingw
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

USE_UPNP:=0

MAKE=make-mingw32

INCLUDEPATHS= \
-I"C:\boost-1.49.0-mgw" \
-I"C:\db-4.8.30.NC-mgw\build_unix" \
Expand Down Expand Up @@ -36,6 +38,12 @@ ifdef USE_UPNP
DEFS += -DSTATICLIB -DUSE_UPNP=$(USE_UPNP)
endif

ifdef USE_NATIVE_I2P
DEFS += -DUSE_NATIVE_I2P -I../i2psam/
LIBS += -L../i2psam/
LIBS += -li2psam
endif

LIBS += -l kernel32 -l user32 -l gdi32 -l comdlg32 -l winspool -l winmm -l shell32 -l comctl32 -l ole32 -l oleaut32 -l uuid -l rpcrt4 -l advapi32 -l ws2_32 -l mswsock -l shlwapi

# TODO: make the mingw builds smarter about dependencies, like the linux/osx builds are
Expand Down Expand Up @@ -76,8 +84,18 @@ obj/scrypt.o: scrypt.c
obj/%.o: %.cpp $(HEADERS)
g++ -c $(CFLAGS) -o $@ $<

ifdef USE_NATIVE_I2P
anoncoind.exe: i2psam $(OBJS:obj/%=obj/%)
g++ $(CFLAGS) -o $@ $(LIBPATHS) $(OBJS) $(LIBS)
else
anoncoind.exe: $(OBJS:obj/%=obj/%)
g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS)
endif

ifdef USE_NATIVE_I2P
i2psam:
$(MAKE) -C ../i2psam -f makefile.mingw
endif

TESTOBJS := $(patsubst test/%.cpp,obj-test/%.o,$(wildcard test/*.cpp))

Expand All @@ -88,6 +106,9 @@ test_anoncoin.exe: $(TESTOBJS) $(filter-out obj/init.o,$(OBJS:obj/%=obj/%))
g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ -lboost_unit_test_framework $(LIBS)

clean:
ifdef USE_NATIVE_I2P
$(MAKE) -C ../i2psam -f makefile.mingw clean
endif
-del /Q anoncoind test_anoncoin
-del /Q obj\*
-del /Q obj-test\*
Expand Down
20 changes: 19 additions & 1 deletion src/makefile.unix
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ LIBS+= \
-l dl \
-l pthread

ifdef USE_NATIVE_I2P
DEFS += -DUSE_NATIVE_I2P -I../i2psam/
LIBS += -L../i2psam/
LIBS += -li2psam
endif

# Hardening
# Make some classes of vulnerabilities unexploitable in case one is discovered.
Expand Down Expand Up @@ -141,8 +146,18 @@ obj/%.o: %.cpp
-e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
rm -f $(@:%.o=%.d)

ifdef USE_NATIVE_I2P
anoncoind: i2psam $(OBJS:obj/%=obj/%)
$(CXX) $(xCXXFLAGS) -o $@ $(OBJS) $(xLDFLAGS) $(LIBS)
else
anoncoind: $(OBJS:obj/%=obj/%)
$(CXX) $(xCXXFLAGS) -o $@ $^ $(xLDFLAGS) $(LIBS)
$(CXX) $(xCXXFLAGS) -o $@ $^ $(xLDFLAGS) $(LIBS)
endif

ifdef USE_NATIVE_I2P
i2psam:
$(MAKE) -C ../i2psam -f makefile.unix
endif

TESTOBJS := $(patsubst test/%.cpp,obj-test/%.o,$(wildcard test/*.cpp))

Expand All @@ -157,6 +172,9 @@ test_anoncoin: $(TESTOBJS) $(filter-out obj/init.o,$(OBJS:obj/%=obj/%))
$(CXX) $(xCXXFLAGS) -o $@ $(LIBPATHS) $^ -Wl,-B$(LMODE) -lboost_unit_test_framework $(xLDFLAGS) $(LIBS)

clean:
ifdef USE_NATIVE_I2P
$(MAKE) -C ../i2psam -f makefile.unix clean
endif
-rm -f anoncoind test_anoncoin
-rm -f obj/*.o
-rm -f obj-test/*.o
Expand Down
14 changes: 14 additions & 0 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#include <string.h>
#endif

#ifdef USE_NATIVE_I2P
#include "i2p.h"
#endif

#ifdef USE_UPNP
#include <miniupnpc/miniwget.h>
#include <miniupnpc/miniupnpc.h>
Expand Down Expand Up @@ -50,7 +54,13 @@ struct LocalServiceInfo {
bool fClient = false;
bool fDiscover = true;
bool fUseUPnP = false;

#ifdef USE_NATIVE_I2P
uint64 nLocalServices = NODE_I2P | (fClient ? 0 : NODE_NETWORK);
#else
uint64 nLocalServices = (fClient ? 0 : NODE_NETWORK);
#endif

static CCriticalSection cs_mapLocalHost;
static map<CNetAddr, LocalServiceInfo> mapLocalHost;
static bool vfReachable[NET_MAX] = {};
Expand All @@ -61,6 +71,10 @@ array<int, THREAD_MAX> vnThreadsRunning;
static std::vector<SOCKET> vhListenSocket;
CAddrMan addrman;

#ifdef USE_NATIVE_I2P
static std::vector<SOCKET> vhI2PListenSocket;
#endif

vector<CNode*> vNodes;
CCriticalSection cs_vNodes;
map<CInv, CDataStream> mapRelay;
Expand Down

0 comments on commit dc00622

Please sign in to comment.