2005-01-24 smeghead
* C#-ification of sam-sharp: interface greatly simplified using delegates and events; SamBaseEventHandler provides basic implementation and helper methods but is now optional. * NAnt buildfile and README added for sam-sharp.
This commit is contained in:
84
apps/sam/csharp/src/I2P.SAM.Client/README
Normal file
84
apps/sam/csharp/src/I2P.SAM.Client/README
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
sam-sharp
|
||||||
|
|
||||||
|
|
||||||
|
DESCRIPTION
|
||||||
|
|
||||||
|
sam-sharp is a .NET SAM client library for I2P written in C#. It aims to be
|
||||||
|
compatible with platforms that implement .NET's base class library API (such
|
||||||
|
as Mono and DotGNU Portable.NET) and to be usable from all languages
|
||||||
|
conforming to the ECMA-standardized Common Language Infrastructure, including
|
||||||
|
C# and VB.NET.
|
||||||
|
|
||||||
|
|
||||||
|
MINIMUM REQUIREMENTS
|
||||||
|
|
||||||
|
* Mono and mcs 1.0 or higher (Linux, Mac OS X, Windows)
|
||||||
|
|
||||||
|
- or -
|
||||||
|
|
||||||
|
MS .NET Framework SDK 1.0 or higher (Windows)
|
||||||
|
|
||||||
|
- or -
|
||||||
|
|
||||||
|
DotGNU Portable .NET, latest version recommended (*BSD, AIX, Cygwin, Linux,
|
||||||
|
Mac OS X, MinGW, Solaris)
|
||||||
|
|
||||||
|
|
||||||
|
OPTIONAL REQUIREMENTS
|
||||||
|
|
||||||
|
* NAnt 0.85 or higher is needed to use sam-sharp.build. Sorry, NAnt does not
|
||||||
|
yet support Portable.NET.
|
||||||
|
|
||||||
|
* NUnit 2.2.1 or later is needed to run the (soon-to-be-added) unit tests. If
|
||||||
|
you have the Mono mcs package installed then you already have NUnit.
|
||||||
|
|
||||||
|
|
||||||
|
DOCUMENTATION
|
||||||
|
|
||||||
|
Pre-generated docs will be submitted to CVS soon. In the meantime you may
|
||||||
|
generate standalone documentation from the embedded XML doc comments by
|
||||||
|
issuing the following commands from sam-sharp's src/ directory:
|
||||||
|
|
||||||
|
Mono:
|
||||||
|
|
||||||
|
mkdir ../doc
|
||||||
|
mcs -doc:../doc/sam-sharp_doc.xml *.cs
|
||||||
|
|
||||||
|
MS .NET:
|
||||||
|
|
||||||
|
mkdir ../doc
|
||||||
|
csc /doc:../doc/sam-sharp_doc.xml *.cs
|
||||||
|
|
||||||
|
DotGNU Portable.NET:
|
||||||
|
|
||||||
|
mkdir ../doc
|
||||||
|
csdoc -o ../doc/sam-sharp_doc.xml *.cs
|
||||||
|
|
||||||
|
The resulting XML doc can be converted to HTML using either Visual Studio .NET
|
||||||
|
(Tools > Build Comment Web Pages) or Portable.NET's csdoc2html tool:
|
||||||
|
|
||||||
|
csdoc2html -o ../doc ../doc/sam-sharp_doc.xml
|
||||||
|
|
||||||
|
|
||||||
|
ACKNOWLEDGMENTS
|
||||||
|
|
||||||
|
sam-sharp is a port of jrandom's public domain Java SAM client library.
|
||||||
|
|
||||||
|
|
||||||
|
LICENSE
|
||||||
|
|
||||||
|
This work is released into the public domain.
|
||||||
|
|
||||||
|
|
||||||
|
AUTHORS
|
||||||
|
|
||||||
|
jrandom (original Java SAM client library)
|
||||||
|
smeghead (C# port of the Java SAM client library)
|
||||||
|
|
||||||
|
|
||||||
|
MAINTAINERS
|
||||||
|
|
||||||
|
smeghead <smeghead@i2pmail.org> <smeghead@mail.i2p>
|
||||||
|
|
||||||
|
|
||||||
|
$Id$
|
160
apps/sam/csharp/src/I2P.SAM.Client/SamBaseEventHandler.cs
Normal file
160
apps/sam/csharp/src/I2P.SAM.Client/SamBaseEventHandler.cs
Normal file
@ -0,0 +1,160 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Specialized;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
namespace I2P.SAM.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Optional base class providing basic SAM event handling and helper
|
||||||
|
/// methods.
|
||||||
|
/// </summary>
|
||||||
|
public class SamBaseEventHandler
|
||||||
|
{
|
||||||
|
private object _helloLock = new Object();
|
||||||
|
private string _helloOk;
|
||||||
|
private NameValueCollection _namingReplies = new NameValueCollection();
|
||||||
|
private object _namingReplyLock = new Object();
|
||||||
|
private SamReader _samReader;
|
||||||
|
private object _sessionCreateLock = new Object();
|
||||||
|
private string _sessionCreateOk;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new <c>SamBaseEventHandler</c> instance and registers
|
||||||
|
/// overridable handler methods for all events generated by the given
|
||||||
|
/// <see cref="SamReader">SamReader</see>.
|
||||||
|
/// </summary>
|
||||||
|
public SamBaseEventHandler(SamReader samReader) {
|
||||||
|
_samReader = samReader;
|
||||||
|
_samReader.DestReplyReceived += new DestReplyReceivedHandler(OnDestReplyReceived);
|
||||||
|
_samReader.HelloReplyReceived += new HelloReplyReceivedHandler(OnHelloReplyReceived);
|
||||||
|
_samReader.NamingReplyReceived += new NamingReplyReceivedHandler(OnNamingReplyReceived);
|
||||||
|
_samReader.SessionStatusReceived += new SessionStatusReceivedHandler(OnSessionStatusReceived);
|
||||||
|
_samReader.StreamClosedReceived += new StreamClosedReceivedHandler(OnStreamClosedReceived);
|
||||||
|
_samReader.StreamConnectedReceived += new StreamConnectedReceivedHandler(OnStreamConnectedReceived);
|
||||||
|
_samReader.StreamDataReceived += new StreamDataReceivedHandler(OnStreamDataReceived);
|
||||||
|
_samReader.StreamStatusReceived += new StreamStatusReceivedHandler(OnStreamStatusReceived);
|
||||||
|
_samReader.UnknownMessageReceived += new UnknownMessageReceivedHandler(OnUnknownMessageReceived);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnDestReplyReceived(string publicKey, string privateKey) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnHelloReplyReceived(bool ok) {
|
||||||
|
lock (_helloLock) {
|
||||||
|
if (ok)
|
||||||
|
_helloOk = Boolean.TrueString;
|
||||||
|
else
|
||||||
|
_helloOk = Boolean.FalseString;
|
||||||
|
|
||||||
|
Monitor.PulseAll(_helloLock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnNamingReplyReceived(string name, string result, string valueString, string message) {
|
||||||
|
lock (_namingReplyLock) {
|
||||||
|
if (result.Equals(SamBridgeMessages.NAMING_REPLY_OK))
|
||||||
|
_namingReplies.Add(name, valueString);
|
||||||
|
else
|
||||||
|
_namingReplies.Add(name, result);
|
||||||
|
|
||||||
|
Monitor.PulseAll(_namingReplyLock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnSessionStatusReceived(string result, string destination, string message) {
|
||||||
|
lock (_sessionCreateLock) {
|
||||||
|
if (result.Equals(SamBridgeMessages.SESSION_STATUS_OK))
|
||||||
|
_sessionCreateOk = Boolean.TrueString;
|
||||||
|
else
|
||||||
|
_sessionCreateOk = Boolean.FalseString;
|
||||||
|
|
||||||
|
Monitor.PulseAll(_sessionCreateLock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnStreamClosedReceived(string result, int id, string message) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnStreamConnectedReceived(string remoteDestination, int id) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnStreamDataReceived(int id, byte[] data, int offset, int length) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnStreamStatusReceived(string result, int id, string message) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnUnknownMessageReceived(string major, string minor, NameValueCollection parameters) {
|
||||||
|
Console.WriteLine("wrt, [" + major + "] [" + minor + "] [" + parameters + "]");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper methods below.
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Waits for a SAM connection to be established.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This method blocks until the connection is established.
|
||||||
|
/// </remarks>
|
||||||
|
/// <returns><c>true</c> if the handshake was successful.</returns>
|
||||||
|
public virtual bool WaitForHelloReply() {
|
||||||
|
while (true) {
|
||||||
|
lock (_helloLock) {
|
||||||
|
if (_helloOk == null)
|
||||||
|
Monitor.Wait(_helloLock);
|
||||||
|
else
|
||||||
|
return Boolean.Parse(_helloOk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Waits for a SAM naming reply message.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This method blocks until all naming replies are received.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="name">The name to be looked for, or <c>ME</c>.</param>
|
||||||
|
/// <returns>The matching destination for <c>name</c>, or <c>null</c> if
|
||||||
|
/// the key was not able to be retrieved.</returns>
|
||||||
|
public virtual string WaitForNamingReply(string name) {
|
||||||
|
while (true) {
|
||||||
|
lock (_namingReplyLock) {
|
||||||
|
try {
|
||||||
|
string valueString = _namingReplies[name];
|
||||||
|
_namingReplies.Remove(name);
|
||||||
|
|
||||||
|
if (valueString.Equals(SamBridgeMessages.NAMING_REPLY_INVALID_KEY))
|
||||||
|
return null;
|
||||||
|
else if (valueString.Equals(SamBridgeMessages.NAMING_REPLY_KEY_NOT_FOUND))
|
||||||
|
return null;
|
||||||
|
else
|
||||||
|
return valueString;
|
||||||
|
|
||||||
|
} catch (ArgumentNullException ane) {
|
||||||
|
Monitor.Wait(_namingReplyLock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Waits for a SAM session to be created.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This method blocks until a SAM session is created.
|
||||||
|
/// </remarks>
|
||||||
|
/// <returns><c>true</c> if the SAM session was created successfully.
|
||||||
|
// </returns>
|
||||||
|
public virtual bool WaitForSessionCreateReply() {
|
||||||
|
while (true) {
|
||||||
|
lock (_sessionCreateLock) {
|
||||||
|
if (_sessionCreateOk == null)
|
||||||
|
Monitor.Wait(_sessionCreateLock);
|
||||||
|
else
|
||||||
|
return Boolean.Parse(_sessionCreateOk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,20 +0,0 @@
|
|||||||
using System.Collections.Specialized;
|
|
||||||
|
|
||||||
namespace I2P.SAM.Client
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Async event notification interface for SAM clients.
|
|
||||||
/// </summary>
|
|
||||||
public interface SamClientEventListener
|
|
||||||
{
|
|
||||||
void HelloReplyReceived(bool ok);
|
|
||||||
void SessionStatusReceived(string result, string destination, string message);
|
|
||||||
void StreamStatusReceived(string result, int id, string message);
|
|
||||||
void StreamConnectedReceived(string remoteDestination, int id);
|
|
||||||
void StreamClosedReceived(string result, int id, string message);
|
|
||||||
void StreamDataReceived(int id, byte[] data, int offset, int length);
|
|
||||||
void NamingReplyReceived(string name, string result, string valueString, string message);
|
|
||||||
void DestReplyReceived(string publicKey, string privateKey);
|
|
||||||
void UnknownMessageReceived(string major, string minor, NameValueCollection parameters);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
using System.Collections.Specialized;
|
|
||||||
|
|
||||||
namespace I2P.SAM.Client
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Basic noop client event listener.
|
|
||||||
/// </summary>
|
|
||||||
public class SamClientEventListenerImpl : SamClientEventListener
|
|
||||||
{
|
|
||||||
public virtual void DestReplyReceived(string publicKey, string privateKey) {}
|
|
||||||
public virtual void HelloReplyReceived(bool ok) {}
|
|
||||||
public virtual void NamingReplyReceived(string name, string result, string valueString, string message) {}
|
|
||||||
public virtual void SessionStatusReceived(string result, string destination, string message) {}
|
|
||||||
public virtual void StreamClosedReceived(string result, int id, string message) {}
|
|
||||||
public virtual void StreamConnectedReceived(string remoteDestination, int id) {}
|
|
||||||
public virtual void StreamDataReceived(int id, byte[] data, int offset, int length) {}
|
|
||||||
public virtual void StreamStatusReceived(string result, int id, string message) {}
|
|
||||||
public virtual void UnknownMessageReceived(string major, string minor, NameValueCollection parameters) {}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,116 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Specialized;
|
|
||||||
using System.Threading;
|
|
||||||
|
|
||||||
namespace I2P.SAM.Client
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Simple helper implementation of a SamClientEventListener.
|
|
||||||
/// </summary>
|
|
||||||
public class SamEventHandler : SamClientEventListenerImpl
|
|
||||||
{
|
|
||||||
private object _helloLock = new Object();
|
|
||||||
private String _helloOk;
|
|
||||||
private NameValueCollection _namingReplies = new NameValueCollection();
|
|
||||||
private object _namingReplyLock = new Object();
|
|
||||||
private object _sessionCreateLock = new Object();
|
|
||||||
private String _sessionCreateOk;
|
|
||||||
|
|
||||||
public override void HelloReplyReceived(bool ok) {
|
|
||||||
lock (_helloLock) {
|
|
||||||
if (ok)
|
|
||||||
_helloOk = Boolean.TrueString;
|
|
||||||
else
|
|
||||||
_helloOk = Boolean.FalseString;
|
|
||||||
|
|
||||||
Monitor.PulseAll(_helloLock);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void NamingReplyReceived(string name, string result, string valueString, string message) {
|
|
||||||
lock (_namingReplyLock) {
|
|
||||||
if (result.Equals(SamBridgeMessages.NAMING_REPLY_OK))
|
|
||||||
_namingReplies.Add(name, valueString);
|
|
||||||
else
|
|
||||||
_namingReplies.Add(name, result);
|
|
||||||
|
|
||||||
Monitor.PulseAll(_namingReplyLock);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void SessionStatusReceived(string result, string destination, string message) {
|
|
||||||
lock (_sessionCreateLock) {
|
|
||||||
if (result.Equals(SamBridgeMessages.SESSION_STATUS_OK))
|
|
||||||
_sessionCreateOk = Boolean.TrueString;
|
|
||||||
else
|
|
||||||
_sessionCreateOk = Boolean.FalseString;
|
|
||||||
|
|
||||||
Monitor.PulseAll(_sessionCreateLock);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void UnknownMessageReceived(string major, string minor, NameValueCollection parameters) {
|
|
||||||
Console.WriteLine("wrt, [" + major + "] [" + minor + "] [" + parameters + "]");
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Blocking lookup calls below.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Wait for the connection to be established, returning true if
|
|
||||||
/// everything went ok.
|
|
||||||
/// </summary>
|
|
||||||
public bool WaitForHelloReply() {
|
|
||||||
while (true) {
|
|
||||||
lock (_helloLock) {
|
|
||||||
if (_helloOk == null)
|
|
||||||
Monitor.Wait(_helloLock);
|
|
||||||
else
|
|
||||||
return Boolean.Parse(_helloOk);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Return the destination found matching the name, or <c>null</c> if
|
|
||||||
/// the key was not able to be retrieved.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="name">The name to be looked for, or "ME".</param>
|
|
||||||
public string WaitForNamingReply(string name) {
|
|
||||||
while (true) {
|
|
||||||
lock (_namingReplyLock) {
|
|
||||||
try {
|
|
||||||
string valueString = _namingReplies[name];
|
|
||||||
_namingReplies.Remove(name);
|
|
||||||
|
|
||||||
if (valueString.Equals(SamBridgeMessages.NAMING_REPLY_INVALID_KEY))
|
|
||||||
return null;
|
|
||||||
else if (valueString.Equals(SamBridgeMessages.NAMING_REPLY_KEY_NOT_FOUND))
|
|
||||||
return null;
|
|
||||||
else
|
|
||||||
return valueString;
|
|
||||||
|
|
||||||
} catch (ArgumentNullException ane) {
|
|
||||||
Monitor.Wait(_namingReplyLock);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Wait for the session to be created, returning true if everything
|
|
||||||
/// went ok.
|
|
||||||
/// </summary>
|
|
||||||
public bool WaitForSessionCreateReply() {
|
|
||||||
while (true) {
|
|
||||||
lock (_sessionCreateLock) {
|
|
||||||
if (_sessionCreateOk == null)
|
|
||||||
Monitor.Wait(_sessionCreateLock);
|
|
||||||
else
|
|
||||||
return Boolean.Parse(_sessionCreateOk);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -8,19 +8,37 @@ using System.Threading;
|
|||||||
|
|
||||||
namespace I2P.SAM.Client
|
namespace I2P.SAM.Client
|
||||||
{
|
{
|
||||||
|
public delegate void DestReplyReceivedHandler(string publicKey, string privateKey);
|
||||||
|
public delegate void HelloReplyReceivedHandler(bool ok);
|
||||||
|
public delegate void NamingReplyReceivedHandler(string name, string result, string valueString, string message);
|
||||||
|
public delegate void SessionStatusReceivedHandler(string result, string destination, string message);
|
||||||
|
public delegate void StreamClosedReceivedHandler(string result, int id, string message);
|
||||||
|
public delegate void StreamConnectedReceivedHandler(string remoteDestination, int id);
|
||||||
|
public delegate void StreamDataReceivedHandler(int id, byte[] data, int offset, int length);
|
||||||
|
public delegate void StreamStatusReceivedHandler(string result, int id, string message);
|
||||||
|
public delegate void UnknownMessageReceivedHandler(string major, string minor, NameValueCollection parameters);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Read from a socket, producing events for any SAM message read.
|
/// Reads from a socket stream, producing events for any SAM message read.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SamReader
|
public class SamReader
|
||||||
{
|
{
|
||||||
private bool _isLive;
|
public event DestReplyReceivedHandler DestReplyReceived;
|
||||||
private SamClientEventListener _listener;
|
public event HelloReplyReceivedHandler HelloReplyReceived;
|
||||||
private NetworkStream _samStream;
|
public event NamingReplyReceivedHandler NamingReplyReceived;
|
||||||
private StreamReader _streamReader;
|
public event SessionStatusReceivedHandler SessionStatusReceived;
|
||||||
|
public event StreamClosedReceivedHandler StreamClosedReceived;
|
||||||
|
public event StreamConnectedReceivedHandler StreamConnectedReceived;
|
||||||
|
public event StreamDataReceivedHandler StreamDataReceived;
|
||||||
|
public event StreamStatusReceivedHandler StreamStatusReceived;
|
||||||
|
public event UnknownMessageReceivedHandler UnknownMessageReceived;
|
||||||
|
|
||||||
public SamReader(NetworkStream samStream, SamClientEventListener listener) {
|
private bool _isLive;
|
||||||
|
private NetworkStream _samStream;
|
||||||
|
private StreamReader _samStreamReader;
|
||||||
|
|
||||||
|
public SamReader(NetworkStream samStream) {
|
||||||
_samStream = samStream;
|
_samStream = samStream;
|
||||||
_listener = listener;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RunThread() {
|
public void RunThread() {
|
||||||
@ -31,11 +49,11 @@ namespace I2P.SAM.Client
|
|||||||
|
|
||||||
string line = null;
|
string line = null;
|
||||||
|
|
||||||
_streamReader = new StreamReader(_samStream);
|
_samStreamReader = new StreamReader(_samStream);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
line = _streamReader.ReadLine();
|
line = _samStreamReader.ReadLine();
|
||||||
_streamReader.Close();
|
_samStreamReader.Close();
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
Console.Error.WriteLine("Error reading from SAM: {1}", ioe);
|
Console.Error.WriteLine("Error reading from SAM: {1}", ioe);
|
||||||
} catch (OutOfMemoryException oome) {
|
} catch (OutOfMemoryException oome) {
|
||||||
@ -98,11 +116,11 @@ namespace I2P.SAM.Client
|
|||||||
string result = parameters.Get("RESULT");
|
string result = parameters.Get("RESULT");
|
||||||
|
|
||||||
if (result.Equals("OK"))
|
if (result.Equals("OK"))
|
||||||
_listener.HelloReplyReceived(true);
|
HelloReplyReceived(true);
|
||||||
else
|
else
|
||||||
_listener.HelloReplyReceived(false);
|
HelloReplyReceived(false);
|
||||||
} else {
|
} else {
|
||||||
_listener.UnknownMessageReceived(major, minor, parameters);
|
UnknownMessageReceived(major, minor, parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -115,9 +133,9 @@ namespace I2P.SAM.Client
|
|||||||
string destination = parameters.Get("DESTINATION");
|
string destination = parameters.Get("DESTINATION");
|
||||||
string message = parameters.Get("MESSAGE");
|
string message = parameters.Get("MESSAGE");
|
||||||
|
|
||||||
_listener.SessionStatusReceived(result, destination, message);
|
SessionStatusReceived(result, destination, message);
|
||||||
} else {
|
} else {
|
||||||
_listener.UnknownMessageReceived(major, minor, parameters);
|
UnknownMessageReceived(major, minor, parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -136,9 +154,9 @@ namespace I2P.SAM.Client
|
|||||||
string valueString = parameters.Get("VALUE");
|
string valueString = parameters.Get("VALUE");
|
||||||
string message = parameters.Get("MESSAGE");
|
string message = parameters.Get("MESSAGE");
|
||||||
|
|
||||||
_listener.NamingReplyReceived(name, result, valueString, message);
|
NamingReplyReceived(name, result, valueString, message);
|
||||||
} else {
|
} else {
|
||||||
_listener.UnknownMessageReceived(major, minor, parameters);
|
UnknownMessageReceived(major, minor, parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -150,16 +168,16 @@ namespace I2P.SAM.Client
|
|||||||
string pub = parameters.Get("PUB");
|
string pub = parameters.Get("PUB");
|
||||||
string priv = parameters.Get("PRIV");
|
string priv = parameters.Get("PRIV");
|
||||||
|
|
||||||
_listener.DestReplyReceived(pub, priv);
|
DestReplyReceived(pub, priv);
|
||||||
} else {
|
} else {
|
||||||
_listener.UnknownMessageReceived(major, minor, parameters);
|
UnknownMessageReceived(major, minor, parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default :
|
default :
|
||||||
|
|
||||||
_listener.UnknownMessageReceived(major, minor, parameters);
|
UnknownMessageReceived(major, minor, parameters);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -169,8 +187,8 @@ namespace I2P.SAM.Client
|
|||||||
/*
|
/*
|
||||||
* Would use another tidy switch() statement here but the Mono
|
* Would use another tidy switch() statement here but the Mono
|
||||||
* compiler presently gets variable scopes confused within nested
|
* compiler presently gets variable scopes confused within nested
|
||||||
* switch() contexts. Broken with Mono/mcs 1.0.5, 1.1.3, and SVN
|
* switch() contexts. Nested switch() is broken with Mono/mcs 1.0.5,
|
||||||
* head.
|
* 1.1.3, and SVN head.
|
||||||
*/
|
*/
|
||||||
if (minor.Equals("STATUS")) {
|
if (minor.Equals("STATUS")) {
|
||||||
|
|
||||||
@ -179,9 +197,9 @@ namespace I2P.SAM.Client
|
|||||||
string message = parameters.Get("MESSAGE");
|
string message = parameters.Get("MESSAGE");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
_listener.StreamStatusReceived(result, Int32.Parse(id), message);
|
StreamStatusReceived(result, Int32.Parse(id), message);
|
||||||
} catch {
|
} catch {
|
||||||
_listener.UnknownMessageReceived(major, minor, parameters);
|
UnknownMessageReceived(major, minor, parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (minor.Equals("CONNECTED")) {
|
} else if (minor.Equals("CONNECTED")) {
|
||||||
@ -190,9 +208,9 @@ namespace I2P.SAM.Client
|
|||||||
string id = parameters.Get("ID");
|
string id = parameters.Get("ID");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
_listener.StreamConnectedReceived(destination, Int32.Parse(id));
|
StreamConnectedReceived(destination, Int32.Parse(id));
|
||||||
} catch {
|
} catch {
|
||||||
_listener.UnknownMessageReceived(major, minor, parameters);
|
UnknownMessageReceived(major, minor, parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (minor.Equals("CLOSED")) {
|
} else if (minor.Equals("CLOSED")) {
|
||||||
@ -202,9 +220,9 @@ namespace I2P.SAM.Client
|
|||||||
string message = parameters.Get("MESSAGE");
|
string message = parameters.Get("MESSAGE");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
_listener.StreamClosedReceived(result, Int32.Parse(id), message);
|
StreamClosedReceived(result, Int32.Parse(id), message);
|
||||||
} catch {
|
} catch {
|
||||||
_listener.UnknownMessageReceived(major, minor, parameters);
|
UnknownMessageReceived(major, minor, parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (minor.Equals("RECEIVED")) {
|
} else if (minor.Equals("RECEIVED")) {
|
||||||
@ -224,23 +242,24 @@ namespace I2P.SAM.Client
|
|||||||
bytesRead = _samStream.Read(data, 0, sizeValue);
|
bytesRead = _samStream.Read(data, 0, sizeValue);
|
||||||
|
|
||||||
if (bytesRead != sizeValue) {
|
if (bytesRead != sizeValue) {
|
||||||
_listener.UnknownMessageReceived(major, minor, parameters);
|
UnknownMessageReceived(major, minor, parameters);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
_isLive = false;
|
_isLive = false;
|
||||||
_listener.UnknownMessageReceived(major, minor, parameters);
|
UnknownMessageReceived(major, minor, parameters);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_listener.StreamDataReceived(idValue, data, 0, sizeValue);
|
StreamDataReceived(idValue, data, 0, sizeValue);
|
||||||
} catch (FormatException fe) {
|
} catch (FormatException fe) {
|
||||||
_listener.UnknownMessageReceived(major, minor, parameters);
|
UnknownMessageReceived(major, minor, parameters);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_listener.UnknownMessageReceived(major, minor, parameters);
|
UnknownMessageReceived(major, minor, parameters);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_listener.UnknownMessageReceived(major, minor, parameters);
|
UnknownMessageReceived(major, minor, parameters);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
19
apps/sam/csharp/src/I2P.SAM.Client/sam-sharp.build
Normal file
19
apps/sam/csharp/src/I2P.SAM.Client/sam-sharp.build
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<project basedir="." default="bin" name="sam-sharp">
|
||||||
|
|
||||||
|
<target name="bin" description="Builds assemblies from source">
|
||||||
|
<mkdir dir="bin" />
|
||||||
|
<csc target="dll" output="bin/sam-sharp.dll">
|
||||||
|
<sources>
|
||||||
|
<include name="src/**/*.cs" />
|
||||||
|
</sources>
|
||||||
|
</csc>
|
||||||
|
<echo message="Build complete." />
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="clean" description="Deletes all built assemblies">
|
||||||
|
<delete dir="bin" failonerror="false" />
|
||||||
|
<echo message="Clean complete." />
|
||||||
|
</target>
|
||||||
|
|
||||||
|
</project>
|
@ -1,4 +1,10 @@
|
|||||||
$Id: history.txt,v 1.131 2005/01/21 20:53:02 jrandom Exp $
|
$Id: history.txt,v 1.132 2005/01/23 03:22:11 jrandom Exp $
|
||||||
|
|
||||||
|
2005-01-24 smeghead
|
||||||
|
* C#-ification of sam-sharp: interface greatly simplified using delegates
|
||||||
|
and events; SamBaseEventHandler provides basic implementation and helper
|
||||||
|
methods but is now optional.
|
||||||
|
* NAnt buildfile and README added for sam-sharp.
|
||||||
|
|
||||||
2005-01-23 smeghead
|
2005-01-23 smeghead
|
||||||
* Port the java SAM client library to mono/C# and released into the
|
* Port the java SAM client library to mono/C# and released into the
|
||||||
|
Reference in New Issue
Block a user