From 24089c7165bd7807b21939d82cb6cf42d798637e Mon Sep 17 00:00:00 2001 From: Alan McGovern Date: Thu, 28 May 2009 00:56:54 +0000 Subject: [PATCH] * .: * Dht.cs: * AssemblyInfo.cs: * DhtExtension.csproj: Commit the initial version of the dht extension. svn path=/trunk/monsoon/; revision=134908 --- ChangeLog | 5 ++ DhtExtension/AssemblyInfo.cs | 19 +++++ DhtExtension/ChangeLog | 7 ++ DhtExtension/Dht.cs | 120 +++++++++++++++++++++++++++++++ DhtExtension/DhtExtension.csproj | 53 ++++++++++++++ 5 files changed, 204 insertions(+) create mode 100644 DhtExtension/AssemblyInfo.cs create mode 100644 DhtExtension/ChangeLog create mode 100644 DhtExtension/Dht.cs create mode 100644 DhtExtension/DhtExtension.csproj diff --git a/ChangeLog b/ChangeLog index b44aae8..595a633 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-05-28 Alan McGovern + + * DhtExtension: Commit the initial version of the dht + extension. + 2009-05-25 Alan McGovern * configure.ac: Add a dependency on Mono.Addins.Gui diff --git a/DhtExtension/AssemblyInfo.cs b/DhtExtension/AssemblyInfo.cs new file mode 100644 index 0000000..c5fd81c --- /dev/null +++ b/DhtExtension/AssemblyInfo.cs @@ -0,0 +1,19 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +[assembly: AssemblyTitle("DhtExtension")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: AssemblyVersion("0.8.0")] + +[assembly: AssemblyDelaySign(false)] +[assembly: AssemblyKeyFile("")] + +[assembly: Mono.Addins.Addin ("Dht", "0.8.0")] +[assembly: Mono.Addins.AddinDependency ("Monsoon", "0.20")] \ No newline at end of file diff --git a/DhtExtension/ChangeLog b/DhtExtension/ChangeLog new file mode 100644 index 0000000..26ca09c --- /dev/null +++ b/DhtExtension/ChangeLog @@ -0,0 +1,7 @@ +2009-05-28 Alan McGovern + + * Dht.cs: + * AssemblyInfo.cs: + * DhtExtension.csproj: Commit the initial version of the dht + extension. + diff --git a/DhtExtension/Dht.cs b/DhtExtension/Dht.cs new file mode 100644 index 0000000..fc8f4e9 --- /dev/null +++ b/DhtExtension/Dht.cs @@ -0,0 +1,120 @@ + +using System; +using System.Net; +using MonoTorrent; +using MonoTorrent.Common; +using MonoTorrent.Dht; +using MonoTorrent.Dht.Listeners; +using Mono.Addins; +using Monsoon; +using Gtk; + +namespace DhtExtension +{ + [Extension ("/monsoon/dht")] + public class Dht : Monsoon.IDhtExtension + { + Label label = new Label (); + public event EventHandler PeersFound { + add { engine.PeersFound += value; } + remove { engine.PeersFound -= value; } + } + public event EventHandler StateChanged { + add { engine.StateChanged += value; } + remove { engine.StateChanged -= value; } + } + + DhtEngine engine; + DhtListener listener; + + public Dht () + { + listener = new DhtListener (new IPEndPoint (IPAddress.Any, 35800)); + engine = new DhtEngine (listener); + engine.StateChanged += delegate { UpdateText (); }; + GLib.Timeout.Add (5000, delegate { + UpdateText (); + return true; + }); + } + + void UpdateText () + { + string status; + switch (engine.State) { + case DhtState.Initialising: + status = "Initialising"; + break; + case DhtState.NotReady: + status = "NotReady"; + break; + case DhtState.Ready: + status = "Ready"; + break; + default: + status = ""; + break; + } + int nodes = (int) engine.SaveNodes ().Length / 20; + // FIXME: Hardcoded zero here for the moment, need to get a node count + label.Text = string.Format ("Dht Status: {0}. Nodes: {1}", status, nodes); + } + + public byte[] SaveNodes() + { + return engine.SaveNodes (); + } + + public void Announce(InfoHash infohash, int port) + { + engine.Announce (infohash, port); + } + + public void Dispose () + { + engine.Dispose (); + } + + public void GetPeers(InfoHash infohash) + { + engine.GetPeers (infohash); + } + + public ToolItem GetWidget () + { + UpdateText (); + ToolItem item = new ToolItem (); + HBox box = new HBox (); + box.Add (label); + item.Child = box; + return item; + } + + public void Start() + { + TorrentController c = ServiceManager.Get (); + listener.ChangeEndpoint (new IPEndPoint (IPAddress.Any, c.Engine.Settings.ListenPort)); + engine.Start (); + } + + public void Start(byte[] initialNodes) + { + TorrentController c = ServiceManager.Get (); + listener.ChangeEndpoint (new IPEndPoint (IPAddress.Any, c.Engine.Settings.ListenPort)); + engine.Start (initialNodes); + } + + public void Stop() + { + engine.Stop (); + } + + public bool Disposed { + get { return engine.Disposed; } + } + + public DhtState State { + get { return engine.State; } + } + } +} diff --git a/DhtExtension/DhtExtension.csproj b/DhtExtension/DhtExtension.csproj new file mode 100644 index 0000000..5f855b7 --- /dev/null +++ b/DhtExtension/DhtExtension.csproj @@ -0,0 +1,53 @@ + + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {21BBF2C6-11F3-4006-BA93-E9C8A980AE74} + Library + DhtExtension + + + true + full + false + bin\Debug + DEBUG + prompt + 4 + false + + + none + false + bin\Release + prompt + 4 + false + + + + + + False + ..\Monsoon\bin\Release\Monsoon.exe + + + False + MonoTorrent.Dht.dll + + + False + MonoTorrent.dll + + + + + + + + + + \ No newline at end of file