⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 messages.cs

📁 P2P (peer to peer) file sharing program in C#. Supports Gnutella, Gnutella2, eDonkey, and OpenNap. w
💻 CS
📖 第 1 页 / 共 4 页
字号:
				return new Timestamp();			else if(name == "RA")				return new RetryAfter();			else if(name == "FR")				return new FromAddress();			else				return new UnknownChild(ref name);		}		public class Timestamp : Child		{			public override void Process(int offset, int len)			{				((QueryAck)this.root).timeStamp = Endian.ToInt32(root.inPayload, offset, root.be);			}		}		public class DoneHub : Child		{			public IPAddress ipa;			public override void Process(int offset, int len)			{				this.ipa = Endian.GetIPAddress(root.inPayload, offset);				//add these once in a while				if(GUID.rand.Next(0, 20) == 1)				{					HubInfo hi = new HubInfo();					hi.port = Endian.ToUInt16(root.inPayload, offset+4, root.be);					hi.timeKnown = 0;					HostCache.AddRecentAndCache(this.ipa, hi);				}			}		}		public class SearchHub : Child		{			public override void Process(int offset, int len)			{				if(len != 6 && len != 10)				{					System.Diagnostics.Debug.WriteLine("SearchHub paylen: " + len.ToString());				}				else				{					HubInfo hi = new HubInfo();					hi.port = Endian.ToUInt16(root.inPayload, offset+4, root.be);					if(len == 6)						hi.timeKnown = 0;					else                        hi.timeKnown = Math.Abs(((QueryAck)root).timeStamp - Endian.ToInt32(root.inPayload, offset+6, root.be));					HostCache.AddRecentAndCache(Endian.GetIPAddress(root.inPayload, offset), hi);				}			}		}		public class RetryAfter : Child		{			public override void Process(int offset, int len)			{				if(len == 2)					((QueryAck)root).retry = (int)Endian.ToUInt16(root.inPayload, offset, root.be);				else if(len == 4)					((QueryAck)root).retry = Endian.ToInt32(root.inPayload, offset, root.be);			}		}		public class FromAddress : Child		{			public override void Process(int offset, int len)			{				if(len == 6 || len == 4)					((QueryAck)root).remoteHub = Endian.GetIPAddress(root.inPayload, offset);				else					Utils.Diag("G2 QA FromAddress is wrong length");			}		}	}	public class QueryHit : Message	{		ArrayList qhos = null;		IPEndPoint ipepSender = null;		IPEndPoint ipepNH = null;		byte[] servguid = null;		string vendor = "";		bool supportsChat = false;		bool supportsBrowse = false;		bool szFound = false;		public override void Process(int offset, int len)		{			if(len != 17)				throw new Exception("g2 QH2 packet didn't have guid & hop count");			//potential browse host response			if(root.sockNum != -1)				if(Sck.scks[root.sockNum].browseHost)				{					System.Threading.Thread.Sleep(200);					Child child = this.children;					while(child != null)					{						child.Read(child.offset);						child = child.nextChild;					}					string searchname = "browse: " + Sck.scks[root.sockNum].address;					if(this.qhos != null)						foreach(QueryHitObject qho in this.qhos)						{							qho.browse = true;							qho.chat = this.supportsChat;							qho.guid = Utils.HexGuid(root.inPayload, offset+1, 16);							qho.hops = (int)root.inPayload[offset];							if(ipepSender == null)							{								System.Diagnostics.Debug.WriteLine("q2 qh2 no node address");								return;							}							qho.ip = ipepSender.Address.ToString();							qho.ipepNH = this.ipepNH;							qho.networkType = NetworkType.Gnutella2;							qho.port = ipepSender.Port;							qho.servIdent = this.servguid;							qho.sockWhereFrom = root.sockNum;							qho.speed = 50;							qho.vendor = this.vendor;							GUIBridge.AddQueryHit(qho, null, ref searchname);						}					return;				}			//check if it's for us			if(Search.activeSearches.Count > 0)			{				lock(Search.activeSearches)					foreach(Search search in Search.activeSearches)						if(GUID.Compare(search.guid, 0, root.inPayload, offset+1))						{							if(!search.active)								return;							Child child = this.children;							while(child != null)							{								child.Read(child.offset);								child = child.nextChild;							}							if(this.qhos != null)								foreach(QueryHitObject qho in this.qhos)								{									qho.browse = this.supportsBrowse;									qho.chat = this.supportsChat;									qho.guid = Utils.HexGuid(search.guid);									qho.hops = (int)root.inPayload[offset];									if(ipepSender == null)									{										System.Diagnostics.Debug.WriteLine("q2 qh2 no node address");										return;									}									qho.ip = ipepSender.Address.ToString();									qho.ipepNH = this.ipepNH;									qho.networkType = NetworkType.Gnutella2;									qho.port = ipepSender.Port;									qho.servIdent = this.servguid;									qho.sockWhereFrom = root.sockNum;									qho.speed = 50;									qho.vendor = this.vendor;									GUIBridge.AddQueryHit(qho, null, ref search.query);								}							return;						}			}			//qh2 isn't for us			if(Stats.Updated.Gnutella2.ultrapeer)			{				GUIDitem gitem = new GUIDitem(root.inPayload, offset+1);				Router.RouteEntry re;				lock(Router.htRoutes)				{					if(Router.htRoutes.ContainsKey(gitem))						re = (Router.RouteEntry)Router.htRoutes[gitem];#if	DEBUG					else					{						Utils.Diag("G2 QH2 no route found... maybe requery response?");						goto requery_response;					}#else					else						goto requery_response;#endif				}				OCopy ocopy = new OCopy();				ocopy.payload = root.inPayload;				ocopy.payload[offset]++;	//hop count				ocopy.CreateHeader("QH2", root.be, root.cf);				Router.RoutePacket(ocopy, re);				return;			}		requery_response:			//maybe it's for a downloader... potential requery response			if(Stats.Updated.downloadsNow == 0)				return;			Child child2 = this.children;			while(child2 != null)			{				child2.Read(child2.offset);				child2 = child2.nextChild;			}			if(this.qhos != null)				foreach(QueryHitObject qho in this.qhos)					foreach(DownloadManager dMEr in DownloadManager.dms)						if(dMEr != null)							if(dMEr.active)								if(((Downloader)dMEr.downloaders[0]).qho.networkType == NetworkType.Gnutella2)									if(((Downloader)dMEr.downloaders[0]).qho.sha1sum == qho.sha1sum && qho.sha1sum.Length > 0)									{										//for downloads started via the "Download URL" feature in FileScope										if(dMEr.downloaders.Count == 1 && ((Downloader)dMEr.downloaders[0]).qho.ip == "0.0.0.0")										{											((Downloader)dMEr.downloaders[0]).qho.fileSize = qho.fileSize;											((Downloader)dMEr.downloaders[0]).qho.fileName = qho.fileName;										}										qho.browse = this.supportsBrowse;										qho.chat = this.supportsChat;										qho.guid = Utils.HexGuid(root.inPayload, offset+1, 16);										qho.hops = (int)root.inPayload[offset];										if(ipepSender == null)										{											System.Diagnostics.Debug.WriteLine("q2 qh2 no node address");											return;										}										qho.ip = ipepSender.Address.ToString();										qho.ipepNH = this.ipepNH;										qho.networkType = NetworkType.Gnutella2;										qho.port = ipepSender.Port;										qho.servIdent = this.servguid;										qho.sockWhereFrom = root.sockNum;										qho.speed = 50;										qho.vendor = this.vendor;										ReQuery.AddGnutellaReQueryFoundDownloader(qho, dMEr);									}		}		QueryHitObject GetLatestQHO()		{			return (QueryHitObject)qhos[qhos.Count-1];		}		public override Child ChildType(ref string name)		{			if(name == "H")				return new Hit();			else if(name == "NH")				return new NeighborHub();			else if(name == "HG")				return new HitGroup();			else if(name == "GU")				return new GuIdent();			else if(name == "NA")				return new NodeAddress();			else if(name == "V")				return new VendorCode();			else if(name == "MD")				return new UniMetadata();			else if(name == "UPRO")				return new UserProfile();			else if(name == "BUP")				return new BrowseTag();			else if(name == "PCH")				return new ChatTag();			else				return new UnknownChild(ref name);		}		public class GuIdent : Child		{			public override void Process(int offset, int len)			{				((QueryHit)root).servguid = new byte[16];				Array.Copy(root.inPayload, offset, ((QueryHit)root).servguid, 0, 16);			}		}		public class NodeAddress : Child		{			public override void Process(int offset, int len)			{				if(len == 6)					((QueryHit)root).ipepSender = new IPEndPoint(Endian.GetIPAddress(root.inPayload, offset), Endian.ToUInt16(root.inPayload, offset+4, root.be));				else					System.Diagnostics.Debug.WriteLine("G2 QH2 node address was messed up: " + len.ToString());			}		}		public class NeighborHub : Child		{			public override void Process(int offset, int len)			{				if(len == 6)					((QueryHit)root).ipepNH = new IPEndPoint(Endian.GetIPAddress(root.inPayload, offset), Endian.ToUInt16(root.inPayload, offset+4, root.be));				else					System.Diagnostics.Debug.WriteLine("G2 QH2 neighboring hub address was messed up: " + len.ToString());			}		}		public class VendorCode : Child		{			public override void Process(int offset, int len)			{				if(len == 4)					((QueryHit)root).vendor = Gnutella.Vendor.GetVendor(Encoding.ASCII.GetString(root.inPayload, offset, 4));			}		}		public class BrowseTag : Child		{			public override void Process(int offset, int len)			{				((QueryHit)root).supportsBrowse = true;			}		}		public class ChatTag : Child		{			public override void Process(int offset, int len)			{				((QueryHit)root).supportsChat = true;			}		}		public class HitGroup : Child		{			public override void Process(int offset, int len)			{				//			}			public override Child ChildType(ref string name)			{				if(name == "SS")					return new ServerState();				else					return new UnknownChild(ref name);			}			public class ServerState : Child			{				public override void Process(int offset, int len)				{					//				}			}		}		public class Hit : Child		{			public override void Process(int offset, int len)			{				if(((QueryHit)root).qhos == null)					((QueryHit)root).qhos = new ArrayList(2);				((QueryHit)root).qhos.Add(new QueryHitObject());				Child child = this.children;				while(child != null)				{					child.Read(child.offset);					child = child.nextChild;				}			}			public override Child ChildType(ref string name)			{				if(name == "URN")					return new URN();				else if(name == "URL")					return new URL();				else if(name == "DN")					return new DescName();				else if(name == "MD")					return new Metadata();				else if(name == "SZ")					return new Size();				else if(name == "G")					return new Group();				else if(name == "ID")					return new ID();				else if(name == "CSC")					return new CachedSourceCount();				else if(name == "PART")					return new Part();				else if(name == "COM")					return new Comment();				else if(name == "PVU")					return new Preview();				else					return new UnknownChild(ref name);			}			public class URN : Child			{				public override void Process(int offset, int len)				{					string strURN = Utils.GetString(root.inPayload, offset, len);					if(strURN.Substring(0, 2) == "bp" && len == 47)						((QueryHit)root).GetLatestQHO().sha1sum = "urn:sha1:" + Base32.Encode(root.inPayload, offset+3, 20);					else if(strURN.Substring(0, 8) == "bitprint" && len == 53)						((QueryHit)root).GetLatestQHO().sha1sum = "urn:sha1:" + Base32.Encode(root.inPayload, offset+9, 20);					else if(strURN.Substring(0, 4) == "sha1" && len == 25)						((QueryHit)root).GetLatestQHO().sha1sum = "urn:sha1:" + Base32.Encode(root.inPayload, offset+5, 20);					else if(strURN.Substring(0, 4) == "ed2k" && len == 21)					{						((QueryHit)root).GetLatestQHO().md4sum = new byte[16];						Array.Copy(root.inPayload, offset+5, ((QueryHit)root).GetLatestQHO().md4sum, 0, 16);					}				}			}			public class URL : Child			{				public override void Process(int offset, int len)				{					if(len > 0)						System.Diagnostics.Debug.WriteLine("g2 url unsupported: " + Utils.GetString(root.inPayload, offset, len));				}			}			public class DescName : Child			{				public override void Process(int offset, int len)				{					if(!((QueryHit)root).szFound)					{						((QueryHit)root).GetLatestQHO().fileSize = Endian.ToUInt32(root.inPayload, offset, root.be);						offset += 4;						len -= 4;					}					((QueryHit)root).GetLatestQHO().fileName = Utils.GetString(root.inPayload, offset, len);				}			}			public class Metadata : Child			{				public override void Process(int offset, int len)				{					//				}			}			public class Size : Child			{				public override void Process(int offset, int len)				{					if(len != 4 && len != 8)						throw new Exception("g2 QH2/H/SZ len not supported: " + len.ToString());					if(len == 4)						((QueryHit)root).GetLatestQHO().fileSize = Endian.ToUInt32(root.inPayload, offset, root.be);					else if(len == 8)					{						ulong tmpulong = Endian.ToUInt64(root.inPayload, offset, root.be);						if(tmpulong < uint.MaxValue)							((QueryHit)root).GetLatestQHO().fileSize = (uint)tmpulong;						else							throw new Exception("g2 QH2/H/SZ len too big!");					}					((QueryHit)root).szFound = true;				}			}			public class Group : Child			{				public override void Process(int offset, int len)				{					//				}			}			public class ID : Child			{				public override void Process(int offset, int len)				{					//as of right now, we don't touch ((QueryHit)root).GetLatestQHO().fileIndex, so it's available				}			}			public class CachedSourceCount : Child			{				public override void Process(int offset, int len)				{					//				}			}			public class Part : Child			{				public override void Process(int offset, int len)				{					System.Diagnostics.Debug.WriteLine("g2 partial file: " + Endian.ToUInt32(root.inPayload, offset, root.be).ToString());				}			}			public class Comment : Child			{				public override void Process(int offset, int len)				{					//				}			}			public class Preview : Child			{				public override void Process(int offset, int len)				{					//				}			}		}		public class UniMetadata : Child		{			public override void Process(int offset, int len)			{				//			}		}		public class UserProfile : Child		{			public override void Process(int offset, int len)			{				//			}			public override Child ChildType(ref string name)			{				if(name == "NICK")					return new NickName();				else					return new UnknownChild(ref name);			}			public class NickName : Child			{				public override void Process(int offset, int len)				{					//				}			}		}	}	public class UserProfileRequest : Message	{		public override void Process(int offset, int len)		{			//		}	}	public class UserProfileAnswer : Message	{		public override void Process(int offset, int len)		{			//		}	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -