From dc0062218107d6515c8e588317a17c35040e96b3 Mon Sep 17 00:00:00 2001 From: Meeh Date: Sat, 8 Jun 2013 16:59:11 +0200 Subject: [PATCH] Adding I2P code. Still some more to do before it's ready. --- .../{makefile.linux-mingw => makefile.mingw} | 0 src/addrman.h | 4 +++ src/init.cpp | 26 +++++++++++++++++++ src/main.cpp | 12 +++++++++ src/makefile.mingw | 21 +++++++++++++++ src/makefile.unix | 20 +++++++++++++- src/net.cpp | 14 ++++++++++ 7 files changed, 96 insertions(+), 1 deletion(-) rename i2psam/{makefile.linux-mingw => makefile.mingw} (100%) diff --git a/i2psam/makefile.linux-mingw b/i2psam/makefile.mingw similarity index 100% rename from i2psam/makefile.linux-mingw rename to i2psam/makefile.mingw diff --git a/src/addrman.h b/src/addrman.h index 039265436..321339c18 100644 --- a/src/addrman.h +++ b/src/addrman.h @@ -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 diff --git a/src/init.cpp b/src/init.cpp index 5fbca71a3..2d9f10f07 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -20,6 +20,10 @@ #include #endif +#ifdef USE_NATIVE_I2P +#include "i2p.h" +#endif + using namespace std; using namespace boost; @@ -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)) @@ -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() { @@ -330,6 +342,16 @@ bool AppInit2() // ********************************************************* Step 2: parameter interactions +#ifdef USE_NATIVE_I2P + if (GetBoolArg(I2P_SAM_GENERATE_DESTINATION_PARAM)) { + const std::pair 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) @@ -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.")); diff --git a/src/main.cpp b/src/main.cpp index 14b6fbc9d..5e704dd5d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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) { @@ -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 } diff --git a/src/makefile.mingw b/src/makefile.mingw index 3e51a3177..1d04e26b8 100644 --- a/src/makefile.mingw +++ b/src/makefile.mingw @@ -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" \ @@ -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 @@ -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)) @@ -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\* diff --git a/src/makefile.unix b/src/makefile.unix index 19448a4d9..6ef171586 100644 --- a/src/makefile.unix +++ b/src/makefile.unix @@ -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. @@ -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)) @@ -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 diff --git a/src/net.cpp b/src/net.cpp index c9f8b59cf..2b64beef9 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -16,6 +16,10 @@ #include #endif +#ifdef USE_NATIVE_I2P +#include "i2p.h" +#endif + #ifdef USE_UPNP #include #include @@ -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 mapLocalHost; static bool vfReachable[NET_MAX] = {}; @@ -61,6 +71,10 @@ array vnThreadsRunning; static std::vector vhListenSocket; CAddrMan addrman; +#ifdef USE_NATIVE_I2P +static std::vector vhI2PListenSocket; +#endif + vector vNodes; CCriticalSection cs_vNodes; map mapRelay;