Author: alanmc
Date: 2006-09-10 08:04:57 -0400 (Sun, 10 Sep 2006)
New Revision: 65161

Added:
   branches/BitSharp/bitsharp/src/MonoTorrent.Client/PeerConnections/
   
branches/BitSharp/bitsharp/src/MonoTorrent.Client/PeerConnections/HTTPConnection.cs
   
branches/BitSharp/bitsharp/src/MonoTorrent.Client/PeerConnections/PeerConnectionBase.cs
   
branches/BitSharp/bitsharp/src/MonoTorrent.Client/PeerConnections/PeerConnectionId.cs
   
branches/BitSharp/bitsharp/src/MonoTorrent.Client/PeerConnections/TCPConnection.cs
Log:
Structure for HTTPConnection, TCPConnection and PeerConnectionBase now finalised

Added: 
branches/BitSharp/bitsharp/src/MonoTorrent.Client/PeerConnections/HTTPConnection.cs
===================================================================
--- 
branches/BitSharp/bitsharp/src/MonoTorrent.Client/PeerConnections/HTTPConnection.cs
 2006-09-10 12:04:27 UTC (rev 65160)
+++ 
branches/BitSharp/bitsharp/src/MonoTorrent.Client/PeerConnections/HTTPConnection.cs
 2006-09-10 12:04:57 UTC (rev 65161)
@@ -0,0 +1,50 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using MonoTorrent.Client.Encryption;
+
+namespace MonoTorrent.Client.PeerConnections
+{
+    public class HTTPConnection : PeerConnectionBase
+    {
+        public HTTPConnection(string location, int bitfieldLength, IEncryptor 
encryptor)
+            : base(bitfieldLength, encryptor)
+        {
+            throw new NotImplementedException();
+        }
+        internal override void BeginConnect(AsyncCallback 
peerEndCreateConnection, PeerConnectionID id)
+        {
+            throw new NotImplementedException();
+        }
+
+        internal override void BeginReceive(byte[] buffer, int offset, int 
count, System.Net.Sockets.SocketFlags socketFlags, AsyncCallback asyncCallback, 
PeerConnectionID id)
+        {
+            throw new NotImplementedException();
+        }
+
+        internal override void BeginSend(byte[] buffer, int offset, int count, 
System.Net.Sockets.SocketFlags socketFlags, AsyncCallback asyncCallback, 
PeerConnectionID id)
+        {
+            throw new NotImplementedException();
+        }
+
+        internal override void EndConnect(IAsyncResult result)
+        {
+            throw new NotImplementedException();
+        }
+
+        internal override int EndReceive(IAsyncResult result)
+        {
+            throw new NotImplementedException();
+        }
+
+        internal override int EndSend(IAsyncResult result)
+        {
+            throw new NotImplementedException();
+        }
+
+        public override void Dispose()
+        {
+            throw new NotImplementedException();
+        }
+    }
+}


Property changes on: 
branches/BitSharp/bitsharp/src/MonoTorrent.Client/PeerConnections/HTTPConnection.cs
___________________________________________________________________
Name: svn:eol-style
   + native

Added: 
branches/BitSharp/bitsharp/src/MonoTorrent.Client/PeerConnections/PeerConnectionBase.cs
===================================================================
--- 
branches/BitSharp/bitsharp/src/MonoTorrent.Client/PeerConnections/PeerConnectionBase.cs
     2006-09-10 12:04:27 UTC (rev 65160)
+++ 
branches/BitSharp/bitsharp/src/MonoTorrent.Client/PeerConnections/PeerConnectionBase.cs
     2006-09-10 12:04:57 UTC (rev 65161)
@@ -0,0 +1,315 @@
+//
+// PeerConnectionBase.cs
+//
+// Authors:
+//   Alan McGovern [EMAIL PROTECTED]
+//
+// Copyright (C) 2006 Alan McGovern
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+
+
+using System.Collections.Generic;
+using System.Net.Sockets;
+using System.Net;
+using MonoTorrent.Client.PeerMessages;
+using System;
+using MonoTorrent.Client.Encryption;
+
+namespace MonoTorrent.Client
+{
+    /// <summary>
+    /// Holds the data for a connection to another peer
+    /// </summary>
+    public abstract class PeerConnectionBase : IDisposable
+    {
+        #region Member Variables
+        /// <summary>
+        /// The size of the send and recieve buffers. Defaults to 32bytes more 
than my default request size.
+        /// </summary>
+        private static readonly int BufferSize = ((1 << 14) + 32);
+
+
+        /// <summary>
+        /// The time at which the last message was sent at
+        /// </summary>
+        public DateTime LastMessageSent
+        {
+            get { return this.lastMessageSent; }
+            internal set { this.lastMessageSent = value; }
+        }
+        private DateTime lastMessageSent;
+
+
+        /// <summary>
+        /// The time at which the last message was received at
+        /// </summary>
+        public DateTime LastMessageRecieved
+        {
+            get { return this.lastMessageRecieved; }
+            internal set { this.lastMessageRecieved = value; }
+        }
+        private DateTime lastMessageRecieved;
+
+
+        /// <summary>
+        /// The peers bitfield
+        /// </summary>
+        public BitField BitField
+        {
+            get { return this.bitField; }
+            set { this.bitField = value; }
+        }
+        private BitField bitField;
+
+
+        /// <summary>
+        /// The number of pieces that we've sent the peer.
+        /// </summary>
+        public int PiecesSent
+        {
+            get { return this.piecesSent; }
+            internal set { this.piecesSent = value; }
+        }
+        private int piecesSent;
+
+
+        /// <summary>
+        /// 
+        /// </summary>
+        public int IsRequestingPiecesCount
+        {
+            get { return this.isRequestingPiecesCount; }
+            set { this.isRequestingPiecesCount = value; }
+        }
+        private int isRequestingPiecesCount;
+
+
+        /// <summary>
+        /// 
+        /// </summary>
+        public int AmRequestingPiecesCount
+        {
+            get { return this.amRequestingPiecesCount; }
+            set { this.amRequestingPiecesCount = value; }
+        }
+        private int amRequestingPiecesCount;
+
+
+        /// <summary>
+        /// True if we are currently processing the peers message queue
+        /// </summary>
+        public bool ProcessingQueue
+        {
+            get { return this.processingQueue; }
+            set { this.processingQueue = value; }
+        }
+        private bool processingQueue;
+
+        /// <summary>
+        /// The total bytes to send from the buffer
+        /// </summary>
+        public int BytesToSend
+        {
+            get { return this.bytesToSend; }
+            set { this.bytesToSend = value; }
+        }
+        private int bytesToSend;
+
+
+        /// <summary>
+        /// The total number of bytes sent from the current send buffer
+        /// </summary>
+        public int BytesSent
+        {
+            get { return this.bytesSent; }
+            set { this.bytesSent = value; }
+        }
+        private int bytesSent;
+
+
+        /// <summary>
+        /// The total number of bytes recieved into the current recieve buffer
+        /// </summary>
+        public int BytesRecieved
+        {
+            get { return this.bytesRecieved; }
+            set { this.bytesRecieved = value; }
+        }
+        private int bytesRecieved;
+
+
+        /// <summary>
+        /// The total number of bytes to receive
+        /// </summary>
+        public int BytesToRecieve
+        {
+            get { return this.bytesToRecieve; }
+            set { this.bytesToRecieve = value; }
+        }
+        private int bytesToRecieve;
+
+
+        /// <summary>
+        /// This holds the peermessages waiting to be sent
+        /// </summary>
+        private Queue<IPeerMessage> sendQueue;
+
+
+        internal byte[] recieveBuffer;
+        internal byte[] sendBuffer;
+
+
+        /// <summary>
+        /// The connection Monitor for this peer
+        /// </summary>
+        public ConnectionMonitor Monitor
+        {
+            get { return this.monitor; }
+        }
+        private ConnectionMonitor monitor;
+
+
+        /// <summary>
+        /// True if the peer has some pieces that we need
+        /// </summary>
+        public bool AmInterested
+        {
+            get { return this.amInterested; }
+            internal set { this.amInterested = value; }
+        }
+        private bool amInterested;
+
+
+        /// <summary>
+        /// True if we are currently choking the peer
+        /// </summary>
+        public bool AmChoking
+        {
+            get { return this.amChoking; }
+            internal set { this.amChoking = value; }
+        }
+        private bool amChoking;
+
+
+        /// <summary>
+        /// True if the peer is currently choking us
+        /// </summary>
+        public bool IsChoking
+        {
+            get { return this.isChoking; }
+            internal set { this.isChoking = value; }
+        }
+        private bool isChoking;
+
+
+        /// <summary>
+        /// True if the peer is currently interested in us
+        /// </summary>
+        public bool IsInterested
+        {
+            get { return this.isInterested; }
+            internal set { this.isInterested = value; }
+        }
+        private bool isInterested;
+
+
+        /// <summary>
+        /// The current encryption method being used to encrypt connections
+        /// </summary>
+        public IEncryptor Encryptor
+        {
+            get { return this.encryptor; }
+            internal set { this.encryptor = value; }
+        }
+        private IEncryptor encryptor;
+        #endregion
+
+
+        #region Constructors
+        /// <summary>
+        /// Creates a new connection to the peer at the specified IPEndpoint
+        /// </summary>
+        /// <param name="peerEndpoint">The IPEndpoint to connect to</param>
+        public PeerConnectionBase(int bitfieldLength, IEncryptor encryptor)
+        {
+            this.encryptor = encryptor;
+            this.amChoking = true;
+            this.isChoking = true;
+            this.bitField = new BitField(bitfieldLength);
+            this.monitor = new ConnectionMonitor();
+            this.sendQueue = new Queue<IPeerMessage>(4);
+            this.sendBuffer = new byte[BufferSize];
+            this.recieveBuffer = new byte[BufferSize];
+        }
+        #endregion
+
+
+        #region Methods
+        /// <summary>
+        /// Queues a PeerMessage up to be sent to the remote host
+        /// </summary>
+        /// <param name="msg"></param>
+        public void EnQueue(IPeerMessage msg)
+        {
+            sendQueue.Enqueue(msg);
+        }
+
+
+        /// <summary>
+        /// Returns the PeerMessage at the head of the queue
+        /// </summary>
+        /// <returns></returns>
+        public IPeerMessage DeQueue()
+        {
+            return sendQueue.Dequeue();
+        }
+
+
+        /// <summary>
+        /// The length of the Message queue
+        /// </summary>
+        public int QueueLength
+        {
+            get { return this.sendQueue.Count; }
+        }
+        #endregion
+
+
+        #region Async Methods
+        internal abstract void BeginConnect(System.AsyncCallback 
peerEndCreateConnection, PeerConnectionID id);
+
+        internal abstract void BeginReceive(byte[] buffer, int offset, int 
count, SocketFlags socketFlags, System.AsyncCallback asyncCallback, 
PeerConnectionID id);
+
+        internal abstract void BeginSend(byte[] buffer, int offset, int count, 
SocketFlags socketFlags, System.AsyncCallback asyncCallback, PeerConnectionID 
id);
+
+        internal abstract void EndConnect(System.IAsyncResult result);
+
+        internal abstract int EndReceive(System.IAsyncResult result);
+
+        internal abstract int EndSend(System.IAsyncResult result);
+
+        public abstract void Dispose();
+        #endregion
+
+    }
+}
\ No newline at end of file


Property changes on: 
branches/BitSharp/bitsharp/src/MonoTorrent.Client/PeerConnections/PeerConnectionBase.cs
___________________________________________________________________
Name: svn:eol-style
   + native

Added: 
branches/BitSharp/bitsharp/src/MonoTorrent.Client/PeerConnections/PeerConnectionId.cs
===================================================================
--- 
branches/BitSharp/bitsharp/src/MonoTorrent.Client/PeerConnections/PeerConnectionId.cs
       2006-09-10 12:04:27 UTC (rev 65160)
+++ 
branches/BitSharp/bitsharp/src/MonoTorrent.Client/PeerConnections/PeerConnectionId.cs
       2006-09-10 12:04:57 UTC (rev 65161)
@@ -0,0 +1,129 @@
+//
+// PeerConnectionId.cs
+//
+// Authors:
+//   Alan McGovern [EMAIL PROTECTED]
+//
+// Copyright (C) 2006 Alan McGovern
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+
+
+using MonoTorrent.Common;
+namespace MonoTorrent.Client
+{
+    /// <summary>
+    /// 
+    /// </summary>
+    public class PeerConnectionID : IPeerConnectionID
+    {
+        #region Member Variables
+        /// <summary>
+        /// 
+        /// </summary>
+        public Peer Peer
+        {
+            get { return this.peer; }
+            set { this.peer = value; }
+        }
+        private Peer peer;
+
+        /// <summary>
+        /// 
+        /// </summary>
+        public TorrentManager TorrentManager
+        {
+            get { return this.torrentManager; }
+            set
+            {
+                this.torrentManager = value;
+                this.peer.Connection.BitField = new 
BitField(value.Torrent.Pieces.Length);
+            }
+        }
+        private TorrentManager torrentManager;
+        #endregion
+
+
+        #region Constructors
+        /// <summary>
+        /// Creates a new PeerConnectionID
+        /// </summary>
+        /// <param name="peer"></param>
+        public PeerConnectionID(Peer peer)
+        {
+            this.peer = peer;
+            this.torrentManager = null;
+            this.peer.Connection.BitField = null;
+#warning Is this right?
+        }
+
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="peer"></param>
+        /// <param name="manager"></param>
+        public PeerConnectionID(Peer peer, TorrentManager manager)
+        {
+            this.peer = peer;
+            this.torrentManager = manager;
+        }
+        #endregion
+
+
+        #region Overridden Methods
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="obj"></param>
+        /// <returns></returns>
+        public override bool Equals(object obj)
+        {
+            PeerConnectionID id2 = obj as PeerConnectionID;
+            if (id2 == null)
+                return false;
+
+            return (this.peer.Equals(id2.peer));
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <returns></returns>
+        public override int GetHashCode()
+        {
+            return this.peer.GetHashCode();
+        }
+        #endregion
+
+
+        IPeer IPeerConnectionID.Peer
+        {
+            get { return this.peer; }
+        }
+
+        ITorrentManager IPeerConnectionID.TorrentManager
+        {
+            get { return this.torrentManager; }
+        }
+    }
+}
\ No newline at end of file


Property changes on: 
branches/BitSharp/bitsharp/src/MonoTorrent.Client/PeerConnections/PeerConnectionId.cs
___________________________________________________________________
Name: svn:eol-style
   + native

Added: 
branches/BitSharp/bitsharp/src/MonoTorrent.Client/PeerConnections/TCPConnection.cs
===================================================================
--- 
branches/BitSharp/bitsharp/src/MonoTorrent.Client/PeerConnections/TCPConnection.cs
  2006-09-10 12:04:27 UTC (rev 65160)
+++ 
branches/BitSharp/bitsharp/src/MonoTorrent.Client/PeerConnections/TCPConnection.cs
  2006-09-10 12:04:57 UTC (rev 65161)
@@ -0,0 +1,112 @@
+//
+// TCPConnection.cs
+//
+// Authors:
+//   Alan McGovern [EMAIL PROTECTED]
+//
+// Copyright (C) 2006 Alan McGovern
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Net;
+using System.Net.Sockets;
+
+namespace MonoTorrent.Client.Encryption
+{
+    public class TCPConnection : PeerConnectionBase
+    {
+        #region Member Variables
+        private IPEndPoint peerEndPoint;
+        private Socket peerSocket;
+        #endregion
+
+
+        #region Constructors
+        public TCPConnection(string location, int bitfieldLength, IEncryptor 
encryptor)
+            : base(bitfieldLength, encryptor)
+        {
+            string[] s = location.Split(':');
+            if (s.Length != 2)
+                throw new ArgumentException("Location should be in the form 
ipaddress:port", "location");
+
+            this.peerEndPoint = new IPEndPoint(IPAddress.Parse(s[0]), 
Convert.ToInt32(s[1]));
+            this.peerSocket = new Socket(AddressFamily.InterNetwork, 
SocketType.Stream, ProtocolType.Tcp);
+        }
+
+        public TCPConnection(IPEndPoint endPoint, int bitfieldLength, 
IEncryptor encryptor)
+            : base(bitfieldLength, encryptor)
+        {
+            this.peerEndPoint = endPoint;
+            this.peerSocket = new Socket(AddressFamily.InterNetwork, 
SocketType.Stream, ProtocolType.Tcp);
+        }
+
+        public TCPConnection(Socket socket, int bitfieldLength, IEncryptor 
encryptor)
+            : base(bitfieldLength, encryptor)
+        {
+            this.peerEndPoint = (IPEndPoint)socket.RemoteEndPoint;
+            this.peerSocket = socket;
+        }
+        #endregion
+
+
+        #region Async Methods
+        internal override void BeginConnect(AsyncCallback 
peerEndCreateConnection, PeerConnectionID id)
+        {
+            this.peerSocket.BeginConnect(this.peerEndPoint, 
peerEndCreateConnection, id);
+        }
+
+        internal override void BeginReceive(byte[] buffer, int offset, int 
count, SocketFlags socketFlags, AsyncCallback asyncCallback, PeerConnectionID 
id)
+        {
+            this.peerSocket.BeginReceive(buffer, offset, count, socketFlags, 
asyncCallback, id);
+        }
+
+        internal override void BeginSend(byte[] buffer, int offset, int count, 
SocketFlags socketFlags, AsyncCallback asyncCallback, PeerConnectionID id)
+        {
+            this.peerSocket.BeginSend(buffer, offset, count, socketFlags, 
asyncCallback, id);
+        }
+
+        internal override void EndConnect(IAsyncResult result)
+        {
+            this.peerSocket.EndConnect(result);
+        }
+ 
+        internal override int EndSend(IAsyncResult result)
+        {
+            return this.peerSocket.EndSend(result);
+        }
+
+        internal override int EndReceive(IAsyncResult result)
+        {
+            return this.peerSocket.EndReceive(result);
+        }
+
+        public override void Dispose()
+        {
+            this.peerSocket.Close();
+        }
+        #endregion
+    }
+}


Property changes on: 
branches/BitSharp/bitsharp/src/MonoTorrent.Client/PeerConnections/TCPConnection.cs
___________________________________________________________________
Name: svn:eol-style
   + native

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to