Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
* .:
Browse files Browse the repository at this point in the history
* Dht.cs:
* AssemblyInfo.cs:
* DhtExtension.csproj: Commit the initial version of the dht
  extension.

svn path=/trunk/monsoon/; revision=134908
  • Loading branch information
alanmcgovern committed May 28, 2009
1 parent e3a4d3c commit 24089c7
Show file tree
Hide file tree
Showing 5 changed files with 204 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
@@ -1,3 +1,8 @@
2009-05-28 Alan McGovern <amcgovern@novell.com>

* DhtExtension: Commit the initial version of the dht
extension.

2009-05-25 Alan McGovern <amcgovern@novell.com>

* configure.ac: Add a dependency on Mono.Addins.Gui
Expand Down
19 changes: 19 additions & 0 deletions 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")]
7 changes: 7 additions & 0 deletions DhtExtension/ChangeLog
@@ -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.

120 changes: 120 additions & 0 deletions 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<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; }
}
}
}
53 changes: 53 additions & 0 deletions DhtExtension/DhtExtension.csproj
@@ -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>

0 comments on commit 24089c7

Please sign in to comment.