How to fix G2 to connect automatically (PATCH)

After you have edited the source code, post your patch here.
Forum rules
Home | Wiki | Rules

How to fix G2 to connect automatically (PATCH)

Postby Lanigiro » 25 Sep 2014 12:57

In CHostCacheList::Add there are two occurrences of:

Code: Select all
   if ( ! pAddress->S_un.S_un_b.s_b1 ||
      // Don't add own firewalled IPs
      Network.IsFirewalledAddress( pAddress, TRUE ) ||
      // check against IANA Reserved address.
      Network.IsReserved( pAddress ) ||
      // Check security settings, don't add blocked IPs
      Security.IsDenied( pAddress ) )
      // Bad IP
      return NULL;


Add in


Code: Select all
      || (PROTOCOLID == PROTOCOL_G2 &&
          m_pfnGeoIP_country_code_by_ipnum &&
          m_pGeoIP &&
          strstr("CN TW HK",m_pfnGeoIP_country_code_by_ipnum( m_pGeoIP, htonl( pAddress.s_addr ) )) != NULL)


after Security.isDenied( pAddress ) ) in both instances and the G2 hostcache shouldn't get overrun by GFW'd hubs ever again, without affecting the ability to use hosts in those countries as sources, DC++ hubs, or what-have-you, or to upload to them.
Lanigiro
 
Posts: 186
Joined: 10 Feb 2014 14:19

Re: How to fix G2 to connect automatically (PATCH)

Postby raspopov » 26 Sep 2014 14:57

Thank you. BTW you must use proper forum.

Also this is very em... "wrong" idea, for example Shareaza can be used in China so at that point of view we must block everything except China. :D

Other way: you can enumerate all China IP addresses and create security filters for it.

Or find a bad web-caches polluted with china clients (and exclude it).
User avatar
raspopov
Project Admin
 
Posts: 944
Joined: 13 Jun 2009 12:30
Location: Russian Federation

Re: How to fix G2 to connect automatically (PATCH)

Postby brov » 28 Sep 2014 23:46

Maybe not a correct topic, but...

What about handling that in search manager? As many hubs are put into the cache from QA packets...

Code: Select all
BOOL bLikelyFoxy = (nHubs > 20 && nSuggestedHubs < 6 && nRetryAfter == 300);


A simple, yet effective pattern of a Foxy QA packet. They typically connect to 32 hubs, suggest a few and have retry time of 300 secs. Such acks can be dropped alltogether and sending host banned, for example.
The fastest way to get Foxies in cache is to do a few concurrent searches for a random string. With such filtering (drop/ban only sending node and do not add any provided hubs to the cache, still allowing - probably useless - query hits) I rarely get connection 'lags'.
brov
 
Posts: 87
Joined: 05 Jul 2009 12:15

Re: How to fix G2 to connect automatically (PATCH)

Postby Lanigiro » 25 Oct 2014 18:21

Any solution involving adding security rules to Shareaza (manually or automatically) will cause Shareaza to get slow and wonky, in my experience, as it tends to if there are a bazillion security rules rather than a couple of dozen or so.

Any solution involving banning from outside Shareaza (operating system level or router -- IPtables, firewall rules, PeerBlock, software firewall, etc.) will interfere with non-Shareaza applications, e.g. web browsing, and thus have unwanted side effects.

I don't see a problem with my original suggestion. Even if some people use Shareaza from inside China, they're a minority and furthermore Shareaza could use the net-facing IP of itself to decide whether to exclude the three country codes noted from the G2 cache or exclude everything else. Or if it's asymmetrical, exclude nothing when operated inside China. Or always exclude China from G2 hub list (which is what the code will do if used unmodified). Whatever seems to work best for both sides of the GFW.

If the other suggestion on QA packets would work, maybe modify it to just silently not add to the hostcache, without gumming up Shareaza with (eventually) thousands of security rules that will bog things down. As long as the problem hubs never make it into the G2 hostcache the problem is solved.
Lanigiro
 
Posts: 186
Joined: 10 Feb 2014 14:19

Re: How to fix G2 to connect automatically (PATCH)

Postby brov » 25 Oct 2014 23:49

Another part of problem are KHL packets. Shareaza happily sends KHL/CH (cached hub) with foxy's vendor code and address, causing the pollution. As Shareaza already knows banned vendor code, why not filter out them at receiver side (maybe ban is too hard, just filter them out)? IP range and/or country checks are not required. Just 'trust' KHL packets to some extent. And why it accepts banned vendors in first place?

As for QA packets. I am using that heuristics in Quazaa project and it performs very well (never got any false positive yet, althrough needs more testing).
brov
 
Posts: 87
Joined: 05 Jul 2009 12:15

Re: How to fix G2 to connect automatically (PATCH)

Postby ivan386 » 24 Dec 2014 02:11

I go same way
Code: Select all
Add( _T("Connection"), _T("IgnoreCountry"), &Connection.IgnoreCountry, _T("TW HK CN") );

Code: Select all
BOOL CSecurity::IsIgnoreCountry(const CString& strCountry)
{
   if (!strCountry || strCountry.IsEmpty()) return FALSE;
   return Settings.Connection.IgnoreCountry.Find(strCountry) >= 0;
}

Code: Select all
CHostCacheHostPtr CHostCacheList::Add(const IN_ADDR* pAddress, WORD nPort, DWORD tSeen, LPCTSTR pszVendor, DWORD nUptime, DWORD nCurrentLeaves, DWORD nLeafLimit, LPCTSTR szAddress)
{
...
   if ( ! pHost )
   {
      if (Security.IsIgnoreCountry(theApp.GetCountryCode( *pAddress )))
         return NULL;
...
}



And need todo
Code: Select all
bool CHostCacheHost::CanQuote(const DWORD tNow) const
{
   return
      // A host isn't dead...
      ( m_nFailures == 0 ) &&
      // ...and host isn't expired...
      ( ! IsExpired( tNow ) )&&
      //...we send to host today packets(TCP/UDP) and get correct responce...
       IsChecked();
      // ...then we can tell about it to others!
}


Do not share hosts that not Checked by client as in BitTorrent DHT.
data:application/exe,%B4%09%BA%0D%01%CD%21%B4%08%CD%21%CD%20Hello,World!$
ivan386
 
Posts: 260
Joined: 17 Jun 2009 14:08

Re: How to fix G2 to connect automatically (PATCH)

Postby raspopov » 28 Dec 2014 17:50

I think "IgnoreCountry" option should be spelled as "IgnoredCountry" and has a string_set type. Can you make a patch with changes?
User avatar
raspopov
Project Admin
 
Posts: 944
Joined: 13 Jun 2009 12:30
Location: Russian Federation

Re: How to fix G2 to connect automatically (PATCH)

Postby ivan386 » 03 Jan 2015 00:46

PATCH

Settings.h
Code: Select all
   string_set   IgnoredCountry;


Settings.cpp
Code: Select all
   Add( _T("Connection"), _T("IgnoredCountry"), &Connection.IgnoredCountry, _T("|TW|HK|CN|") );


Security.h
Code: Select all
   BOOL         IsIgnoredCountry(const CString& strCountry);


Security.cpp
Code: Select all
BOOL CSecurity::IsIgnoredCountry(const CString& strCountry)
{
   if (strCountry.IsEmpty()) return FALSE;
   return Settings.Connection.IgnoredCountry.find(strCountry) != Settings.Connection.IgnoredCountry.end();
}


HostCache.cpp
Code: Select all
CHostCacheHostPtr CHostCacheList::Add(const IN_ADDR* pAddress, WORD nPort, DWORD tSeen, LPCTSTR pszVendor, DWORD nUptime, DWORD nCurrentLeaves, DWORD nLeafLimit, LPCTSTR szAddress)
{
...
      if (Security.IsIgnoredCountry(theApp.GetCountryCode( *pAddress )))
         return NULL;
...
}
Attachments
IgnoredCountry.zip
(48.19 KiB) Downloaded 390 times
Last edited by ivan386 on 04 Jan 2015 11:43, edited 1 time in total.
data:application/exe,%B4%09%BA%0D%01%CD%21%B4%08%CD%21%CD%20Hello,World!$
ivan386
 
Posts: 260
Joined: 17 Jun 2009 14:08

Re: How to fix G2 to connect automatically (PATCH)

Postby raspopov » 03 Jan 2015 08:32

What means this code?
Code: Select all
BOOL CSecurity::IsIgnoredCountry(const CString& strCountry)
{
   if (!strCountry
User avatar
raspopov
Project Admin
 
Posts: 944
Joined: 13 Jun 2009 12:30
Location: Russian Federation

Re: How to fix G2 to connect automatically (PATCH)

Postby ivan386 » 04 Jan 2015 11:45

Fixed

Maybe it was a try to catch zero pointer.
data:application/exe,%B4%09%BA%0D%01%CD%21%B4%08%CD%21%CD%20Hello,World!$
ivan386
 
Posts: 260
Joined: 17 Jun 2009 14:08

Re: How to fix G2 to connect automatically (PATCH)

Postby queuesclimber » 04 Jan 2015 19:43

Grmm, it still tries connecting to East Asian Hubs in Network.
But maybe I did understand something wrong, what this patch is for. :)
Or I missed update some settings.
If I get a Shareza in EA, ok.
But please, not a Hub.
User avatar
queuesclimber
 
Posts: 250
Joined: 29 Oct 2013 16:24

Re: How to fix G2 to connect automatically (PATCH)

Postby ivan386 » 04 Jan 2015 21:02

This patch prevents add of TW HK CN hubs in HostCache. It not removes already added. Need to clear cache.
data:application/exe,%B4%09%BA%0D%01%CD%21%B4%08%CD%21%CD%20Hello,World!$
ivan386
 
Posts: 260
Joined: 17 Jun 2009 14:08

Re: How to fix G2 to connect automatically (PATCH)

Postby queuesclimber » 05 Jan 2015 14:51

+1
Great patch.
They are gone. Many, many thanks.
User avatar
queuesclimber
 
Posts: 250
Joined: 29 Oct 2013 16:24

Re: G2 Connect Foxy Flood

Postby skinvista » 05 Jan 2015 16:50

While this patch could be useful to ban a specific country in niche situations,
as-is it still potentially "disallows use" of Shareaza in large regions where you are simply trying to block Foxy.
Indicated by "FOXY" "RAZB" or none, apparently.

See my long-standing solution:
https://sourceforge.net/p/peerproject/code/HEAD/tree/trunk/PeerProject/Security.cpp#l721
User avatar
skinvista
 
Posts: 71
Joined: 13 Jun 2009 16:34
Location: Boston / New York City

Re: How to fix G2 to connect automatically (PATCH)

Postby brov » 11 Jan 2015 02:18

This is not a good solution too. You simply sticked to block Asian countries, so no Asians can use raza. Better to fix KHL/CH handling and temporarily block suspicious hubs (simple heuristics will do the job).
brov
 
Posts: 87
Joined: 05 Jul 2009 12:15

Re: G2 Connect Foxy Flood

Postby skinvista » 11 Jan 2015 19:38

The intention is to block "FOXY" - the country codes are only necessary to catch specific "RAZB" and blanks that are still factors.
And yes, I noticed that I should check for these codes before country as an optimization.
User avatar
skinvista
 
Posts: 71
Joined: 13 Jun 2009 16:34
Location: Boston / New York City

Re: How to fix G2 to connect automatically (PATCH)

Postby ivan386 » 27 Jan 2015 17:47

My path do not ban leafs from that country. It only not add it to host cache. My hub now have 2 leafs from CN.
data:application/exe,%B4%09%BA%0D%01%CD%21%B4%08%CD%21%CD%20Hello,World!$
ivan386
 
Posts: 260
Joined: 17 Jun 2009 14:08

Check host before share

Postby ivan386 » 30 Jan 2015 23:54

Check host before share

Code: Select all
bool CHostCacheHost::CanQuote(const DWORD tNow) const
{
   return
      // A host isn't dead...
      ( m_nFailures == 0 ) &&
      // ...and host isn't expired...
      ( ! IsExpired( tNow ) ) &&
      // ...and we checked this host...
      ( m_nUserLimit > 0 && m_bCheckedLocally );
      // ...then we can tell about it to others!
}
Attachments
HostCache.zip
(8.62 KiB) Downloaded 394 times
data:application/exe,%B4%09%BA%0D%01%CD%21%B4%08%CD%21%CD%20Hello,World!$
ivan386
 
Posts: 260
Joined: 17 Jun 2009 14:08

Re: How to fix G2 to connect automatically (PATCH)

Postby queuesclimber » 22 Feb 2015 16:49

skinvista wrote:The intention is to block "FOXY" ....

It is the first step into right direction. Many users who are not on the Forum maybe drop Raza because they cannot
connect to G2 waiting hours, till the EA-Hubs are downconnected, they don't know about HostCache
User avatar
queuesclimber
 
Posts: 250
Joined: 29 Oct 2013 16:24

Re: How to fix G2 to connect automatically (PATCH)

Postby queuesclimber » 25 Mar 2015 20:07

*BUMP*
skinvista wrote:The intention is to block "FOXY" -

Ryu, please include this into official. It is not last update. But it is first step, removing FOXY from G2
And it works. There are no more EA-Hubs anymore.
But Sources from EA downloading very well, installed 2.7.8.0. ( fastest was 512 KB/sec )
User avatar
queuesclimber
 
Posts: 250
Joined: 29 Oct 2013 16:24

Re: How to fix G2 to connect automatically (PATCH)

Postby ale5000 » 17 Jan 2016 14:59

Why instead of banning TW HK CN host from hostcache they aren't just limited to something like 5% of the hostcache and un-preferred in the connection process?

This should avoid pollution but still keep potentially valid hosts.
ale5000
 
Posts: 66
Joined: 18 Nov 2012 22:56

Re: How to fix G2 to connect automatically (PATCH)

Postby ivan386 » 17 Jan 2016 17:47

Shareaza need to check hosts before share it with others. This eliminates the need to exclude the country from the cache.
data:application/exe,%B4%09%BA%0D%01%CD%21%B4%08%CD%21%CD%20Hello,World!$
ivan386
 
Posts: 260
Joined: 17 Jun 2009 14:08

Re: How to fix G2 to connect automatically (PATCH)

Postby raspopov » 17 Jan 2016 20:06

I don't think Shareaza must share tested hosts only.
User avatar
raspopov
Project Admin
 
Posts: 944
Joined: 13 Jun 2009 12:30
Location: Russian Federation

Re: How to fix G2 to connect automatically (PATCH)

Postby ivan386 » 17 Jan 2016 21:22

BitTorrent DHT work in this way:
Routing Table
Every node maintains a routing table of known good nodes. The nodes in the routing table are used as starting points for queries in the DHT. Nodes from the routing table are returned in response to queries from other nodes.

Not all nodes that we learn about are equal. Some are "good" and some are not. Many nodes using the DHT are able to send queries and receive responses, but are not able to respond to queries from other nodes. It is important that each node's routing table must contain only known good nodes. A good node is a node has responded to one of our queries within the last 15 minutes. A node is also good if it has ever responded to one of our queries and has sent us a query within the last 15 minutes. After 15 minutes of inactivity, a node becomes questionable. Nodes become bad when they fail to respond to multiple queries in a row. Nodes that we know are good are given priority over nodes with unknown status.
...
find_node
... When a node receives a find_node query, it should respond with a key "nodes" and value of a string containing the compact node info for the target node or the K (8) closest good nodes in its own routing table.

http://bittorrent.org/beps/bep_0005.html
data:application/exe,%B4%09%BA%0D%01%CD%21%B4%08%CD%21%CD%20Hello,World!$
ivan386
 
Posts: 260
Joined: 17 Jun 2009 14:08

Re: How to fix G2 to connect automatically (PATCH)

Postby raspopov » 19 Jan 2016 20:44

It's right for BitTorrent DHT only.
User avatar
raspopov
Project Admin
 
Posts: 944
Joined: 13 Jun 2009 12:30
Location: Russian Federation

Re: How to fix G2 to connect automatically (PATCH)

Postby ale5000 » 20 Jan 2016 04:07

What about share hosts from TW HK CN only if tested and all others also if untested?
I think it is a good compromise.
ale5000
 
Posts: 66
Joined: 18 Nov 2012 22:56

Re: How to fix G2 to connect automatically (PATCH)

Postby Haluser5 » 22 Jan 2016 23:48

I installed the current version a few days ago and G2 took 15 minutes to connect because it kept scrolling through TW CN HK hosts. The average user will not wait this long for something to work right. They will say screw it! JMO
Haluser5
 
Posts: 8
Joined: 07 Apr 2014 13:54

Re: How to fix G2 to connect automatically (PATCH)

Postby ale5000 » 24 Jan 2016 04:51

Use the updated DefaultServices.dat here: https://sourceforge.net/p/shareaza/code ... format=raw
It should help a bit because it block empty GWCs and add many working GWCs.
ale5000
 
Posts: 66
Joined: 18 Nov 2012 22:56


Return to Code Submission

Who is online

Users browsing this forum: Bing [Bot] and 1 guest