This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Dht.cs: * AssemblyInfo.cs: * DhtExtension.csproj: Commit the initial version of the dht extension. svn path=/trunk/monsoon/; revision=134908
- Loading branch information
1 parent
e3a4d3c
commit 24089c7
Showing
5 changed files
with
204 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
2009-05-28 Alan McGovern <amcgovern@novell.com> | ||
|
||
* Dht.cs: | ||
* AssemblyInfo.cs: | ||
* DhtExtension.csproj: Commit the initial version of the dht | ||
extension. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<PeersFoundEventArgs> 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 <TorrentController> (); | ||
listener.ChangeEndpoint (new IPEndPoint (IPAddress.Any, c.Engine.Settings.ListenPort)); | ||
engine.Start (); | ||
} | ||
|
||
public void Start(byte[] initialNodes) | ||
{ | ||
TorrentController c = ServiceManager.Get <TorrentController> (); | ||
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; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProductVersion>8.0.50727</ProductVersion> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{21BBF2C6-11F3-4006-BA93-E9C8A980AE74}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AssemblyName>DhtExtension</AssemblyName> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug</OutputPath> | ||
<DefineConstants>DEBUG</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<ConsolePause>false</ConsolePause> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>none</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Release</OutputPath> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<ConsolePause>false</ConsolePause> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="Mono.Addins, Version=0.4.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" /> | ||
<Reference Include="Monsoon, Version=0.20.0.0, Culture=neutral, PublicKeyToken=null"> | ||
<SpecificVersion>False</SpecificVersion> | ||
<HintPath>..\Monsoon\bin\Release\Monsoon.exe</HintPath> | ||
</Reference> | ||
<Reference Include="MonoTorrent.Dht, Version=0.70.0.0, Culture=neutral, PublicKeyToken=null"> | ||
<SpecificVersion>False</SpecificVersion> | ||
<HintPath>MonoTorrent.Dht.dll</HintPath> | ||
</Reference> | ||
<Reference Include="MonoTorrent, Version=0.80.0.0, Culture=neutral, PublicKeyToken=null"> | ||
<SpecificVersion>False</SpecificVersion> | ||
<HintPath>MonoTorrent.dll</HintPath> | ||
</Reference> | ||
<Reference Include="gtk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" /> | ||
<Reference Include="glib-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Dht.cs" /> | ||
<Compile Include="AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> | ||
</Project> |