Ignore:
Timestamp:
May 21, 2010, 4:00:55 PM (12 years ago)
Author:
Paul Lelgemann
Message:
  • Removed unused references and using statement in CrypP2P, PeerToPeer, PeerToPeerBaseProxy

+ Skeleton for P2PEditor

Location:
trunk/CrypPlugins/PeerToPeer
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/PeerToPeer/DHT_CommonManagement.cs

    r1433 r1458  
    11using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    42using System.Text;
    5 using Cryptool.PluginBase.Control;
    63using Cryptool.PluginBase.IO;
    74
     
    3936            PeerId pid = null;
    4037            byte[] byteLoad = p2pControl.DHTload(sTopicName);
    41             if(byteLoad != null)
     38            if (byteLoad != null)
    4239                pid = p2pControl.GetPeerID(byteLoad);
    4340            return pid;
     
    5148        /// <param name="aliveMessageInterval">AliveMessageInterval in milliseconds</param>
    5249        /// <returns>true, if storing value in the DHT was successfull.</returns>
    53         public static bool SetAliveMessageInterval(ref IP2PControl p2pControl, string sTopicName, long aliveMessageInterval)
    54         {
    55             return p2pControl.DHTstore(sTopicName + AliveMsg, System.BitConverter.GetBytes(aliveMessageInterval));
     50        public static bool SetAliveMessageInterval(ref IP2PControl p2pControl, string sTopicName,
     51                                                   long aliveMessageInterval)
     52        {
     53            return p2pControl.DHTstore(sTopicName + AliveMsg, BitConverter.GetBytes(aliveMessageInterval));
    5654        }
    5755
     
    6967            byte[] byteLoad = p2pControl.DHTload(sTopicName + AliveMsg);
    7068            if (byteLoad != null)
    71                 ret = System.BitConverter.ToInt64(byteLoad, 0);
     69                ret = BitConverter.ToInt64(byteLoad, 0);
    7270            return ret;
    7371        }
     
    8684            if (cStream != null && sTopicName != null && sTopicName != String.Empty && p2pControl != null)
    8785            {
    88                 CryptoolStream newEncryptedData = new CryptoolStream();
     86                var newEncryptedData = new CryptoolStream();
    8987                newEncryptedData.OpenRead(cStream.FileName);
    9088                if (newEncryptedData.CanRead)
     
    9290                    // Convert CryptoolStream to an byte Array and store it in the DHT
    9391                    if (newEncryptedData.Length > Int32.MaxValue)
    94                         throw (new Exception("Encrypted Data are too long for this PlugIn. The maximum size of Data is " + Int32.MaxValue + "!"));
    95                     byte[] byteEncryptedData = new byte[newEncryptedData.Length];
     92                        throw (new Exception(
     93                            "Encrypted Data are too long for this PlugIn. The maximum size of Data is " + Int32.MaxValue +
     94                            "!"));
     95                    var byteEncryptedData = new byte[newEncryptedData.Length];
    9696                    int k = newEncryptedData.Read(byteEncryptedData, 0, byteEncryptedData.Length);
    9797                    if (k < byteEncryptedData.Length)
     
    177177
    178178        // new stuff - Arnie 2010.02.02
    179        
     179
    180180        ///// <summary>
    181181        ///// Sets or updates the TimeStamp for the actual Publisher
     
    217217    }
    218218}
    219 
  • trunk/CrypPlugins/PeerToPeer/DebugToFile.cs

    r1433 r1458  
    11using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
     2using System.IO;
    43using System.Text;
    5 using System.IO;
    64
    75namespace Cryptool.Plugins.PeerToPeer.Internal
     
    1210        private static string sPath = @"c:\p2p_debug";
    1311        private static string sFileName = "p2p_debug";
    14         private static string sDateTime = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString()
    15             + DateTime.Now.Day.ToString() + "_" + DateTime.Now.Hour.ToString()
    16             + DateTime.Now.Minute.ToString();
    1712
    18         public static string Path
     13        private static readonly string sDateTime = DateTime.Now.Year + DateTime.Now.Month.ToString()
     14                                                   + DateTime.Now.Day + "_" + DateTime.Now.Hour
     15                                                   + DateTime.Now.Minute;
     16
     17        public static string Path
    1918        {
    2019            get { return sPath; }
    21             private set 
    22             { 
     20            private set
     21            {
    2322                // last character must not be a Backslash!
    2423                if (value.Substring(value.Length - 1, 1) == @"\")
     
    3231        {
    3332            get { return sFileName; }
    34             private set 
     33            private set
    3534            {
    3635                if (value.Substring(value.Length - 3, 1) == ".")
     
    6261                i++;
    6362            }
    64             FileInfo fileInfo = new FileInfo(Path + @"\" + FileName + "_" + sDateTime + ".txt");
     63            var fileInfo = new FileInfo(Path + @"\" + FileName + "_" + sDateTime + ".txt");
    6564            sw = fileInfo.CreateText();
    6665            return sw;
     
    7675                }
    7776                catch (Exception ex)
    78                 { }
     77                {
     78                }
    7979                sw.Close();
    8080                sw.Dispose();
     
    8787        {
    8888            DateTime now = DateTime.Now;
    89             StringBuilder sbTimeStamp = new StringBuilder();
     89            var sbTimeStamp = new StringBuilder();
    9090
    9191            if (now.Hour <= 9)
    9292                sbTimeStamp.Append("0");
    93             sbTimeStamp.Append(now.Hour.ToString() + ".");
     93            sbTimeStamp.Append(now.Hour + ".");
    9494            if (now.Minute <= 9)
    9595                sbTimeStamp.Append("0");
    96             sbTimeStamp.Append(now.Minute.ToString() + ".");
     96            sbTimeStamp.Append(now.Minute + ".");
    9797            if (now.Second <= 9)
    9898                sbTimeStamp.Append("0");
    99             sbTimeStamp.Append(now.Second.ToString() + ":");
     99            sbTimeStamp.Append(now.Second + ":");
    100100            if (now.Millisecond <= 9)
    101101                sbTimeStamp.Append("00");
  • trunk/CrypPlugins/PeerToPeer/IP2PControl.cs

    r1433 r1458  
    1 using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
    5 using Cryptool.PluginBase.Miscellaneous;
    6 using Cryptool.PluginBase.Control;
     1using Cryptool.PluginBase.Control;
    72
    83namespace Cryptool.Plugins.PeerToPeer.Internal
    94{
     5
    106    #region P2P Initialisation Enums
     7
    118    public enum P2PLinkManagerType
    129    {
     
    2118
    2219    public enum P2POverlayType
    23     { 
     20    {
    2421        FullMeshOverlay = 0
    2522    }
     
    5653        /// must respond with a pong message
    5754        /// </summary>
    58         Ping = 4, 
     55        Ping = 4,
    5956        /// <summary>
    6057        /// adequate response to a
     
    9592        Payload = 1
    9693    }
     94
    9795    #endregion
    9896
    9997    public delegate void P2PPayloadMessageReceived(PeerId sender, byte[] data);
     98
    10099    public delegate void P2PSystemMessageReceived(PeerId sender, PubSubMessageType msgType);
    101100
     
    123122        /// <param name="destinationAddress">the address of the destination peer</param>
    124123        void SendToPeer(byte[] data, PeerId destinationAddress);
     124
    125125        /// <summary>
    126126        /// Sends data to the specified peer
     
    129129        /// <param name="destinationAddress">the address of the destination peer</param>
    130130        void SendToPeer(string sData, PeerId destinationAddress);
     131
    131132        /// <summary>
    132133        /// Sends data to the specified peer
  • trunk/CrypPlugins/PeerToPeer/KeySearcherResult.cs

    r1433 r1458  
    11using System;
    22using System.Collections.Generic;
    3 using System.Linq;
    43using System.Text;
    5 using KeySearcher;
    64
    75namespace Cryptool.Plugins.PeerToPeer.Internal
     
    97    public class KeySearcherResult
    108    {
    11         private Encoding enc;
     9        private const int VALUE_SIZE = 8;
     10        private readonly Encoding enc;
    1211
    1312        public KeySearcherResult()
    1413        {
    15             this.enc = UTF8Encoding.UTF8;
     14            enc = Encoding.UTF8;
    1615        }
    1716
    1817        public KeySearcherResult(Encoding encType)
    1918        {
    20             this.enc = encType;
     19            enc = encType;
    2120        }
    2221
     
    2524         * | Dataset count | double-value (8 byte) | string len (1 byte) | string-data (n bytes) | byte len (1 byte) | byte-data (n bytes) |
    2625         *  ------------------------------------------------------------------------------------------------------------------------------- */
     26
    2727        public byte[] SerializeResult(LinkedList<KeySearcher.KeySearcher.ValueKey> resultList)
    2828        {
    29             ByteQueue queueResult = new ByteQueue();
     29            var queueResult = new ByteQueue();
    3030            //amount of list entries
    31             queueResult.Push((byte)resultList.Count);
     31            queueResult.Push((byte) resultList.Count);
    3232
    3333            foreach (KeySearcher.KeySearcher.ValueKey valKey in resultList)
    3434            {
    3535                queueResult.Push(BitConverter.GetBytes(valKey.value));
    36                 queueResult.Push((byte)valKey.key.Length);
     36                queueResult.Push((byte) valKey.key.Length);
    3737                queueResult.Push(enc.GetBytes(valKey.key));
    3838                // maybe this could run into an exception, when decryption byte is longer than 256 bytes!
    3939                if (valKey.decryption.Length > 255)
    4040                {
    41                     queueResult.Push((byte)255);
    42                     byte[] shortDecrypt = new byte[255];
     41                    queueResult.Push(255);
     42                    var shortDecrypt = new byte[255];
    4343                    Buffer.BlockCopy(valKey.decryption, 0, shortDecrypt, 0, 255);
    4444                    queueResult.Push(shortDecrypt);
     
    4646                else
    4747                {
    48                     queueResult.Push((byte)valKey.decryption.Length);
     48                    queueResult.Push((byte) valKey.decryption.Length);
    4949                    queueResult.Push(valKey.decryption);
    5050                }
     
    5353        }
    5454
    55         private const int VALUE_SIZE = 8;
    5655        public LinkedList<KeySearcher.KeySearcher.ValueKey> DeserializeResult(byte[] serializedResult)
    5756        {
    58             ByteQueue resultQueue = new ByteQueue(serializedResult);
    59             LinkedList<KeySearcher.KeySearcher.ValueKey> lstRet = new LinkedList<KeySearcher.KeySearcher.ValueKey>();
     57            var resultQueue = new ByteQueue(serializedResult);
     58            var lstRet = new LinkedList<KeySearcher.KeySearcher.ValueKey>();
    6059
    61             KeySearcher.KeySearcher.ValueKey valKey = new KeySearcher.KeySearcher.ValueKey();
     60            var valKey = new KeySearcher.KeySearcher.ValueKey();
    6261            int stringLen = 0;
    6362            int byteLen = 0;
     
    7978        }
    8079
     80        #region Nested type: ByteQueue
     81
    8182        private class ByteQueue
    8283        {
    83             private Queue<byte> myQueue;
    84 
    85             public int CurrentStackSize { get { return myQueue.Count; } }
     84            private readonly Queue<byte> myQueue;
    8685
    8786            public ByteQueue()
     
    9796                    myQueue.Enqueue(data[i]);
    9897                }
     98            }
     99
     100            public int CurrentStackSize
     101            {
     102                get { return myQueue.Count; }
    99103            }
    100104
     
    120124            public byte[] PopBytes(int num)
    121125            {
    122                 byte[] ret = new byte[num];
     126                var ret = new byte[num];
    123127                for (int i = 0; i < num; i++)
    124128                {
     
    133137            }
    134138        }
     139
     140        #endregion
    135141    }
    136142}
  • trunk/CrypPlugins/PeerToPeer/PeedId.cs

    r1433 r1458  
    1 using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
    5 using PeersAtPlay.P2POverlay;
     1using PeersAtPlay.P2POverlay;
    62
    73namespace Cryptool.Plugins.PeerToPeer.Internal
     
    95    public class PeerId
    106    {
    11         private readonly string stringId;
    12         private readonly byte[] byteId;
    13 
    147        private const uint OFFSET_BASIS = 2166136261;
    158        private const uint PRIME = 16777619; // 2^24 + 2^8 + 0x93
     9        private readonly byte[] byteId;
    1610        private readonly int hashCode;
     11        private readonly string stringId;
    1712
    1813        public PeerId(OverlayAddress oAddress)
     
    2015            if (oAddress != null)
    2116            {
    22                 this.stringId = oAddress.ToString();
    23                 this.byteId = oAddress.ToByteArray();
     17                stringId = oAddress.ToString();
     18                byteId = oAddress.ToByteArray();
    2419
    2520                // FNV-1 hashing
     
    2722                foreach (byte b in byteId)
    2823                {
    29                     fnvHash = (fnvHash * PRIME) ^ b;
     24                    fnvHash = (fnvHash*PRIME) ^ b;
    3025                }
    31                 hashCode = (int)fnvHash;
     26                hashCode = (int) fnvHash;
    3227            }
    3328        }
     
    4540                return false;
    4641
    47             if (object.ReferenceEquals(this, right))
     42            if (ReferenceEquals(this, right))
    4843                return true;
    4944
    50             if (this.GetType() != right.GetType())
     45            if (GetType() != right.GetType())
    5146                return false;
    5247
    5348            // actual content comparison
    54             return this == (PeerId)right;
     49            return this == (PeerId) right;
    5550        }
    5651
     
    5954            // because it's possible that one parameter is null, catch this exception
    6055            /* Begin add - Christian Arnold, 2009.12.16, must cast the parameters, otherwise --> recursion */
    61             if ((object)left == (object)right)
     56            if (left == (object) right)
    6257                return true;
    6358
    64             if ((object)left == null || (object)right == null)
     59            if ((object) left == null || (object) right == null)
    6560                return false;
    6661            /* End add */
     
    9489        public override string ToString()
    9590        {
    96             return this.stringId;
     91            return stringId;
    9792        }
    9893
    9994        public byte[] ToByteArray()
    10095        {
    101             return this.byteId;
     96            return byteId;
    10297        }
    10398    }
  • trunk/CrypPlugins/PeerToPeer/PeerToPeer.csproj

    r1451 r1458  
    99    <OutputType>Library</OutputType>
    1010    <AppDesignerFolder>Properties</AppDesignerFolder>
    11     <RootNamespace>Cryptool.Plugins.PeerToPeer</RootNamespace>
     11    <RootNamespace>Cryptool.Plugins.PeerToPeer.Internal</RootNamespace>
    1212    <AssemblyName>PeerToPeer</AssemblyName>
    1313    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
     
    115115  </PropertyGroup>
    116116  <ItemGroup>
    117     <Reference Include="Bootstrapper, Version=1.0.4654.4, Culture=neutral, PublicKeyToken=95429f90c3a66dd4, processorArchitecture=MSIL">
    118       <SpecificVersion>False</SpecificVersion>
    119       <HintPath>..\..\AppReferences\Bootstrapper.dll</HintPath>
    120     </Reference>
    121     <Reference Include="CertServices, Version=1.0.4654.4, Culture=neutral, PublicKeyToken=95429f90c3a66dd4, processorArchitecture=MSIL">
    122       <SpecificVersion>False</SpecificVersion>
    123       <HintPath>..\..\AppReferences\CertServices.dll</HintPath>
    124     </Reference>
    125     <Reference Include="FullMeshDHT, Version=1.0.4654.4, Culture=neutral, PublicKeyToken=95429f90c3a66dd4, processorArchitecture=MSIL">
    126       <SpecificVersion>False</SpecificVersion>
    127       <HintPath>..\..\AppReferences\FullMeshDHT.dll</HintPath>
    128     </Reference>
    129     <Reference Include="FullMeshOverlay, Version=1.0.4654.4, Culture=neutral, PublicKeyToken=95429f90c3a66dd4, processorArchitecture=MSIL">
    130       <SpecificVersion>False</SpecificVersion>
    131       <HintPath>..\..\AppReferences\FullMeshOverlay.dll</HintPath>
    132     </Reference>
    133     <Reference Include="Gears4Net, Version=1.0.4654.4, Culture=neutral, PublicKeyToken=95429f90c3a66dd4, processorArchitecture=MSIL">
    134       <SpecificVersion>False</SpecificVersion>
    135       <HintPath>..\..\AppReferences\Gears4Net.dll</HintPath>
    136     </Reference>
    137     <Reference Include="LinkManager, Version=1.0.4654.4, Culture=neutral, PublicKeyToken=95429f90c3a66dd4, processorArchitecture=MSIL">
    138       <SpecificVersion>False</SpecificVersion>
    139       <HintPath>..\..\AppReferences\LinkManager.dll</HintPath>
    140     </Reference>
    141     <Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=95429f90c3a66dd4, processorArchitecture=MSIL">
    142       <SpecificVersion>False</SpecificVersion>
    143       <HintPath>..\..\AppReferences\log4net.dll</HintPath>
    144     </Reference>
    145     <Reference Include="NetGearsTCP, Version=1.0.0.0, Culture=neutral, PublicKeyToken=95429f90c3a66dd4, processorArchitecture=MSIL">
    146       <SpecificVersion>False</SpecificVersion>
    147       <HintPath>..\..\AppReferences\NetGearsTCP.dll</HintPath>
    148     </Reference>
    149117    <Reference Include="PeersAtPlayBase, Version=1.0.4654.4, Culture=neutral, PublicKeyToken=95429f90c3a66dd4, processorArchitecture=MSIL">
    150118      <SpecificVersion>False</SpecificVersion>
    151119      <HintPath>..\..\AppReferences\PeersAtPlayBase.dll</HintPath>
    152120    </Reference>
    153     <Reference Include="RUDP, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
    154       <SpecificVersion>False</SpecificVersion>
    155       <HintPath>..\..\AppReferences\RUDP.dll</HintPath>
    156     </Reference>
    157     <Reference Include="Stun, Version=1.0.0.0, Culture=neutral, PublicKeyToken=95429f90c3a66dd4, processorArchitecture=MSIL">
    158       <SpecificVersion>False</SpecificVersion>
    159       <HintPath>..\..\AppReferences\Stun.dll</HintPath>
    160     </Reference>
    161121    <Reference Include="System" />
    162     <Reference Include="System.Core">
    163       <RequiredTargetFramework>3.5</RequiredTargetFramework>
    164     </Reference>
    165     <Reference Include="System.Xml.Linq">
    166       <RequiredTargetFramework>3.5</RequiredTargetFramework>
    167     </Reference>
    168     <Reference Include="System.Data.DataSetExtensions">
    169       <RequiredTargetFramework>3.5</RequiredTargetFramework>
    170     </Reference>
    171     <Reference Include="System.Data" />
    172     <Reference Include="System.Xml" />
    173     <Reference Include="Util, Version=0.0.0.0, Culture=neutral, PublicKeyToken=95429f90c3a66dd4, processorArchitecture=MSIL">
    174       <SpecificVersion>False</SpecificVersion>
    175       <HintPath>..\..\AppReferences\Util.dll</HintPath>
    176     </Reference>
    177122  </ItemGroup>
    178123  <ItemGroup>
  • trunk/CrypPlugins/PeerToPeer/ResponseWait.cs

    r1433 r1458  
    1 using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
    5 using System.Threading;
     1using System.Threading;
    62
    73namespace Cryptool.Plugins.PeerToPeer.Internal
     
    95    public class ResponseWait
    106    {
    11         public AutoResetEvent WaitHandle = null;
    12         public byte[] Message = null;
    13         public string key = null;
    14         public byte[] value = null;
     7        public byte[] Message;
     8        public AutoResetEvent WaitHandle;
     9        public string key;
    1510
    16         public bool success = false;
     11        public bool success;
     12        public byte[] value;
    1713    }
    18 
    1914}
Note: See TracChangeset for help on using the changeset viewer.