Changeset 1458 for trunk


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
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypP2P/CrypP2P.csproj

    r1451 r1458  
    8181      <Private>False</Private>
    8282    </Reference>
    83     <Reference Include="CertServices">
    84       <HintPath>..\AppReferences\CertServices.dll</HintPath>
    85       <Private>False</Private>
    86     </Reference>
    87     <Reference Include="DevComponents.WpfDock">
    88       <HintPath>..\AppExternalReferences\DevComponents.WpfDock.dll</HintPath>
    89       <Private>False</Private>
    90     </Reference>
    91     <Reference Include="DevComponents.WpfEditors">
    92       <HintPath>..\AppExternalReferences\DevComponents.WpfEditors.dll</HintPath>
    93       <Private>False</Private>
    94     </Reference>
    9583    <Reference Include="DevComponents.WpfRibbon">
    9684      <HintPath>..\AppExternalReferences\DevComponents.WpfRibbon.dll</HintPath>
     
    113101      <Private>False</Private>
    114102    </Reference>
    115     <Reference Include="log4net">
    116       <HintPath>..\AppReferences\log4net.dll</HintPath>
    117       <Private>False</Private>
    118     </Reference>
    119     <Reference Include="NetGearsTCP">
    120       <HintPath>..\AppReferences\NetGearsTCP.dll</HintPath>
    121       <Private>False</Private>
    122     </Reference>
    123103    <Reference Include="PeersAtPlayBase">
    124104      <HintPath>..\AppReferences\PeersAtPlayBase.dll</HintPath>
     
    131111      <RequiredTargetFramework>3.0</RequiredTargetFramework>
    132112    </Reference>
    133     <Reference Include="Stun">
    134       <HintPath>..\AppReferences\Stun.dll</HintPath>
    135       <Private>False</Private>
    136     </Reference>
    137113    <Reference Include="System" />
    138     <Reference Include="System.Core">
    139       <RequiredTargetFramework>3.5</RequiredTargetFramework>
    140     </Reference>
    141114    <Reference Include="System.Security" />
    142115    <Reference Include="System.Windows.Forms" />
    143116    <Reference Include="System.Xaml" />
    144     <Reference Include="System.Xml.Linq">
    145       <RequiredTargetFramework>3.5</RequiredTargetFramework>
    146     </Reference>
    147     <Reference Include="System.Data.DataSetExtensions">
    148       <RequiredTargetFramework>3.5</RequiredTargetFramework>
    149     </Reference>
    150     <Reference Include="System.Data" />
    151     <Reference Include="System.Xml" />
    152117    <Reference Include="Util">
    153118      <HintPath>..\AppReferences\Util.dll</HintPath>
  • trunk/CrypP2P/Helper/PAPCertificate.cs

    r1374 r1458  
    11using System;
    22using System.Collections.Generic;
    3 using System.Linq;
    43using System.Text;
    54using System.Security.Cryptography.X509Certificates;
  • trunk/CrypP2P/Internal/P2PBase.cs

    r1436 r1458  
    1616using System;
    1717using System.Collections.Generic;
    18 using System.Linq;
    1918using System.Text;
    2019using PeersAtPlay.P2PStorage.DHT;
     
    2726using PeersAtPlay.P2POverlay.Bootstrapper.IrcBootstrapper;
    2827using System.Threading;
    29 using Cryptool.PluginBase.Control;
    30 using System.ComponentModel;
    3128using PeersAtPlay;
    3229using PeersAtPlay.Util.Logging;
     
    151148        #region Basic P2P Methods (Init, Start, Stop) - synch and asynch
    152149
    153         public void Initialize(P2PSettings p2pSettings)
    154         {
    155             Initialize(p2pSettings.PeerName, p2pSettings.WorldName,
    156                 (P2PLinkManagerType)p2pSettings.LinkManagerType, (P2PBootstrapperType)p2pSettings.BSType,
    157                 (P2POverlayType)p2pSettings.OverlayType, (P2PDHTType)p2pSettings.DhtType);
     150        public void Initialize(P2PSettings p2PSettings)
     151        {
     152            Initialize(p2PSettings.PeerName, p2PSettings.WorldName,
     153                (P2PLinkManagerType)p2PSettings.LinkManagerType, (P2PBootstrapperType)p2PSettings.BsType,
     154                (P2POverlayType)p2PSettings.OverlayType, (P2PDHTType)p2PSettings.DhtType);
    158155        }
    159156
  • trunk/CrypP2P/P2PManager.cs

    r1438 r1458  
    1616
    1717using System;
    18 using System.Collections.Generic;
    19 using System.Text;
    20 using System.ComponentModel;
    21 
     18using System.Windows.Forms;
     19using Cryptool.P2P.Internal;
     20using Cryptool.P2P.Worker;
    2221using Cryptool.PluginBase;
    2322using Cryptool.PluginBase.Miscellaneous;
    24 using System.Windows.Forms;
    25 using Cryptool.P2P.Worker;
     23using Cryptool.Plugins.PeerToPeer.Internal;
    2624using DevComponents.WpfRibbon;
    27 using Cryptool.Plugins.PeerToPeer;
    28 using Cryptool.Plugins.PeerToPeer.Internal;
    29 using Cryptool.P2P.Internal;
    3025
    3126namespace Cryptool.P2P
     
    3429    {
    3530        #region Singleton
    36         static readonly P2PManager INSTANCE = new P2PManager();
    37         private P2PManager() { }
    3831
    39         public static P2PManager Instance
     32        public static readonly P2PManager Instance = new P2PManager();
     33
     34        private P2PManager()
    4035        {
    41             get
    42             {
    43                 return INSTANCE;
    44             }
    4536        }
     37
    4638        #endregion
    4739
    4840        # region Constants
    49         public const string P2PDisconnectImageURI = "images/peer2peer-disconnect.png";
    50         public const string P2PConnectImageURI = "images/peer2peer-connect.png";
     41
     42        public const string P2PDisconnectImageUri = "images/peer2peer-disconnect.png";
     43        public const string P2PConnectImageUri = "images/peer2peer-connect.png";
     44
    5145        # endregion
    5246
    5347        #region Private variables
     48
    5449        public P2PBase P2PBase { get; set; }
    5550        private P2PSettings P2PSettings { get; set; }
    5651        private ButtonDropDown P2PButton { get; set; }
     52
    5753        #endregion
    5854
    5955        #region Events
    60         public static event Cryptool.PluginBase.GuiLogNotificationEventHandler OnGuiLogNotificationOccured;
     56
     57        public static event GuiLogNotificationEventHandler OnGuiLogNotificationOccured;
    6158
    6259        // to forward event from overlay/dht MessageReceived-Event from P2PBase
    6360        public event P2PBase.P2PMessageReceived OnPeerMessageReceived;
     61
    6462        #endregion Events
    6563
     
    6866        /// regarding certificates.
    6967        /// </summary>
    70         /// <param name="p2pButton">Button that can change the connection state
     68        /// <param name="p2PButton">Button that can change the connection state
    7169        /// and displays it by showing different images.</param>
    72         public void Initialize(ButtonDropDown p2pButton)
     70        public void Initialize(ButtonDropDown p2PButton)
    7371        {
    74             this.P2PButton = p2pButton;
    75             this.P2PBase = new P2PBase();
    76             this.P2PSettings = new P2PSettings();
    77             this.P2PBase.AllowLoggingToMonitor = this.P2PSettings.Log2Monitor;
     72            P2PButton = p2PButton;
     73            P2PBase = new P2PBase();
     74            P2PSettings = new P2PSettings();
     75            P2PBase.AllowLoggingToMonitor = P2PSettings.Log2Monitor;
    7876
    7977            // Register events
    8078
    8179            // to forward event from overlay/dht MessageReceived-Event from P2PBase
    82             this.P2PBase.OnP2PMessageReceived += new P2PBase.P2PMessageReceived(p2pBase_OnP2PMessageReceived);
     80            P2PBase.OnP2PMessageReceived += p2pBase_OnP2PMessageReceived;
    8381
    8482            // Register exit event to terminate P2P connection without loosing data
    8583            // TODO check if this is correct, should be - but handler is not called (and application does not shut down), probably unrelated to this problem
    86             Application.ApplicationExit += new EventHandler(HandleDisconnectByApplicationShutdown);
     84            Application.ApplicationExit += HandleDisconnectByApplicationShutdown;
    8785        }
    8886
     
    115113        }
    116114
    117         #region DHT operations
    118         // TODO add error handling, if P2P if not connected
    119         public static bool Store(string key, byte[] data)
    120         {
    121             return INSTANCE.P2PBase.SynchStore(key, data);
    122         }
    123 
    124          public static bool Store(string key, string data)
    125         {
    126             return INSTANCE.P2PBase.SynchStore(key, data);
    127         }
    128 
    129         public static byte[] Retrieve(string key)
    130         {
    131             return INSTANCE.P2PBase.SynchRetrieve(key);
    132         }
    133 
    134         public static bool Remove(string key)
    135         {
    136             return INSTANCE.P2PBase.SynchRemove(key);
    137         }
    138         #endregion DHT operations
    139 
    140115        // to forward event from overlay/dht MessageReceived-Event from P2PBase
    141116        private void p2pBase_OnP2PMessageReceived(PeerId sourceAddr, byte[] data)
     
    146121
    147122        #region Framework methods
    148         void HandleDisconnectByApplicationShutdown(object sender, EventArgs e)
     123
     124        private void HandleDisconnectByApplicationShutdown(object sender, EventArgs e)
    149125        {
    150126            if (P2PConnected())
     
    158134            EventsHelper.GuiLogMessage(OnGuiLogNotificationOccured, null, new GuiLogEventArgs(message, null, logLevel));
    159135        }
     136
    160137        #endregion Framework methods
     138
     139        #region DHT operations
     140
     141        // TODO add error handling, if P2P is not connected
     142        public static bool Store(string key, byte[] data)
     143        {
     144            return Instance.P2PBase.SynchStore(key, data);
     145        }
     146
     147        public static bool Store(string key, string data)
     148        {
     149            return Instance.P2PBase.SynchStore(key, data);
     150        }
     151
     152        public static byte[] Retrieve(string key)
     153        {
     154            return Instance.P2PBase.SynchRetrieve(key);
     155        }
     156
     157        public static bool Remove(string key)
     158        {
     159            return Instance.P2PBase.SynchRemove(key);
     160        }
     161
     162        #endregion DHT operations
    161163    }
    162164}
  • trunk/CrypP2P/P2PSettings.cs

    r1433 r1458  
    1515*/
    1616
    17 using System;
    18 using System.Collections.Generic;
    19 using System.Linq;
    20 using System.Text;
    2117using Cryptool.P2P.Helper;
    2218using Cryptool.P2P.Internal;
     
    2723    public class P2PSettings
    2824    {
    29         public P2PBase Base { get; set; }
    30         public string PeerName { get; set; }
    31         public string WorldName { get; set; }
    32         public bool Log2Monitor { get; set; }
    33         public P2PLinkManagerType LinkManagerType { get; set; }
    34         public P2PBootstrapperType BSType { get; set; }
    35         public P2POverlayType OverlayType { get; set; }
    36         public P2PDHTType DhtType { get; set; }
    37 
    3825        public P2PSettings()
    3926        {
     
    4229            Log2Monitor = true;
    4330            LinkManagerType = P2PLinkManagerType.Snal;
    44             BSType = P2PBootstrapperType.IrcBootstrapper;
     31            BsType = P2PBootstrapperType.IrcBootstrapper;
    4532            OverlayType = P2POverlayType.FullMeshOverlay;
    4633            DhtType = P2PDHTType.FullMeshDHT;
    4734        }
     35
     36        public P2PBase Base { get; set; }
     37        public string PeerName { get; set; }
     38        public string WorldName { get; set; }
     39        public bool Log2Monitor { get; set; }
     40        public P2PLinkManagerType LinkManagerType { get; set; }
     41        public P2PBootstrapperType BsType { get; set; }
     42        public P2POverlayType OverlayType { get; set; }
     43        public P2PDHTType DhtType { get; set; }
    4844    }
    4945}
  • trunk/CrypP2P/Properties/AssemblyInfo.cs

    r1366 r1458  
    1616
    1717using System.Reflection;
    18 using System.Runtime.CompilerServices;
    1918using System.Runtime.InteropServices;
    2019
  • trunk/CrypP2P/Worker/ConnectionWorker.cs

    r1438 r1458  
    1616
    1717using System;
    18 using System.Collections.Generic;
    19 using System.Linq;
    20 using System.Text;
     18using System.ComponentModel;
     19using System.Windows.Controls;
     20using System.Windows.Media;
     21using System.Windows.Media.Imaging;
     22using Cryptool.P2P.Helper;
     23using Cryptool.P2P.Internal;
     24using Cryptool.PluginBase;
    2125using DevComponents.WpfRibbon;
    22 using System.Windows.Controls;
    23 using System.Windows.Media.Imaging;
    24 using System.Windows.Media;
    25 using Cryptool.PluginBase;
    26 using Cryptool.P2P.Internal;
    27 using Cryptool.P2P.Helper;
    2826
    2927namespace Cryptool.P2P.Worker
    3028{
    31     class ConnectionWorker : WorkerBase
     29    internal class ConnectionWorker : WorkerBase
    3230    {
    33         P2PBase p2pBase;
    34         P2PSettings p2pSettings;
    35         ButtonDropDown p2pButton;
     31        private readonly P2PBase _p2PBase;
     32        private readonly ButtonDropDown _p2PButton;
     33        private readonly P2PSettings _p2PSettings;
    3634
    37         public ConnectionWorker(P2PBase p2pBase, P2PSettings p2pSettings, ButtonDropDown p2pButton)
     35        public ConnectionWorker(P2PBase p2PBase, P2PSettings p2PSettings, ButtonDropDown p2PButton)
    3836        {
    39             this.p2pBase = p2pBase;
    40             this.p2pSettings = p2pSettings;
    41             this.p2pButton = p2pButton;
     37            _p2PBase = p2PBase;
     38            _p2PSettings = p2PSettings;
     39            _p2PButton = p2PButton;
    4240        }
    4341
    44         protected override void PerformWork(object sender, System.ComponentModel.DoWorkEventArgs e)
     42        protected override void PerformWork(object sender, DoWorkEventArgs e)
    4543        {
    4644            //p2pButton.IsEnabled = false;
    4745
    48             if (!p2pBase.Started)
     46            if (!_p2PBase.Started)
    4947            {
    5048                P2PManager.Instance.GuiLogMessage("Connecting to P2P network...", NotificationLevel.Info);
     
    5351                if (!PAPCertificate.CheckAndInstallPAPCertificates())
    5452                {
    55                     P2PManager.Instance.GuiLogMessage("Certificates not validated, P2P might not be working!", NotificationLevel.Error);
     53                    P2PManager.Instance.GuiLogMessage("Certificates not validated, P2P might not be working!",
     54                                                      NotificationLevel.Error);
    5655                    return;
    5756                }
    5857
    59                 p2pBase.Initialize(p2pSettings);
    60                 p2pBase.SynchStart();
     58                _p2PBase.Initialize(_p2PSettings);
     59                _p2PBase.SynchStart();
    6160            }
    6261            else
    6362            {
    6463                P2PManager.Instance.GuiLogMessage("Disconnecting from P2P network...", NotificationLevel.Info);
    65                 p2pBase.SynchStop();
     64                _p2PBase.SynchStop();
    6665            }
    6766        }
    6867
    69         protected override void WorkComplete(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
     68        protected override void WorkComplete(object sender, RunWorkerCompletedEventArgs e)
    7069        {
    7170            // Update image according to new state
    72             Image newImage = new Image();
     71            var newImage = new Image();
    7372
    7473            if (P2PManager.Instance.P2PConnected())
    7574            {
    7675                P2PManager.Instance.GuiLogMessage("Connection to P2P network established.", NotificationLevel.Info);
    77                 P2PManager.Instance.GuiLogMessage("P2P user info: " + P2PManager.Instance.UserInfo(), NotificationLevel.Debug);
    78                 newImage.Source = new BitmapImage(new Uri(P2PManager.P2PDisconnectImageURI, UriKind.RelativeOrAbsolute));
     76                P2PManager.Instance.GuiLogMessage("P2P user info: " + P2PManager.Instance.UserInfo(),
     77                                                  NotificationLevel.Debug);
     78                newImage.Source = new BitmapImage(new Uri(P2PManager.P2PDisconnectImageUri, UriKind.RelativeOrAbsolute));
    7979            }
    8080            else
    8181            {
    8282                P2PManager.Instance.GuiLogMessage("Connection to P2P network terminated.", NotificationLevel.Info);
    83                 newImage.Source = new BitmapImage(new Uri(P2PManager.P2PConnectImageURI, UriKind.RelativeOrAbsolute));
     83                newImage.Source = new BitmapImage(new Uri(P2PManager.P2PConnectImageUri, UriKind.RelativeOrAbsolute));
    8484            }
    8585
     
    8787            newImage.Width = 40;
    8888            newImage.Height = 40;
    89             p2pButton.Image = newImage;
     89            _p2PButton.Image = newImage;
    9090
    91             p2pButton.IsEnabled = true;
     91            _p2PButton.IsEnabled = true;
    9292        }
    9393
    9494        protected override void PrePerformWork()
    9595        {
    96             p2pButton.IsEnabled = false;
     96            _p2PButton.IsEnabled = false;
    9797        }
    9898    }
  • trunk/CrypP2P/Worker/WorkerBase.cs

    r1374 r1458  
    1515*/
    1616
    17 using System;
    18 using System.Collections.Generic;
    19 using System.Linq;
    20 using System.Text;
    2117using System.ComponentModel;
    2218
    2319namespace Cryptool.P2P.Worker
    2420{
     21    internal abstract class WorkerBase
     22    {
     23        protected BackgroundWorker BackgroundWorker;
    2524
    26     abstract class WorkerBase
    27     {
    28         protected BackgroundWorker backgroundWorker;
    29 
    30         public WorkerBase()
     25        protected WorkerBase()
    3126        {
    32             backgroundWorker = new BackgroundWorker();
    33             backgroundWorker.DoWork += new DoWorkEventHandler(PerformWork);
    34             backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(WorkComplete);
     27            BackgroundWorker = new BackgroundWorker();
     28            BackgroundWorker.DoWork += PerformWork;
     29            BackgroundWorker.RunWorkerCompleted += WorkComplete;
    3530        }
    3631
     
    3833        {
    3934            PrePerformWork();
    40             backgroundWorker.RunWorkerAsync();
     35            BackgroundWorker.RunWorkerAsync();
    4136        }
    4237
  • 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}
  • trunk/CrypPlugins/PeerToPeerBaseProxy/P2PPeer.cs

    r1443 r1458  
    1616
    1717using System;
    18 using System.Collections.Generic;
    19 using System.Linq;
     18using System.ComponentModel;
    2019using System.Text;
    2120using System.Threading;
    22 using Cryptool.PluginBase.Control;
    23 using Cryptool.PluginBase;
    24 using Cryptool.PluginBase.Miscellaneous;
    25 using System.ComponentModel;
    26 using Cryptool.PluginBase.IO;
    27 using Cryptool.Plugins.PeerToPeer.Internal;
     21using System.Windows.Controls;
    2822using Cryptool.P2P;
    2923using Cryptool.P2P.Internal;
     24using Cryptool.PluginBase;
     25using Cryptool.PluginBase.Control;
     26using Cryptool.PluginBase.IO;
     27using Cryptool.PluginBase.Miscellaneous;
     28using Cryptool.Plugins.PeerToPeer.Internal;
    3029
    3130namespace Cryptool.Plugins.PeerToPeerProxy
    3231{
    3332    [Author("Paul Lelgemann", "lelgemann@cryptool.org", "Uni Duisburg-Essen", "http://www.uni-due.de")]
    34     [PluginInfo(false, "P2P_Peer_Proxy", "Creates a new Peer. Uses the CrypTool2 built-in P2P network and can be used as a replacement for P2P_Peer.", "", "PeerToPeerBaseProxy/icons/peer_inactive.png", "PeerToPeerBaseProxy/icons/peer_connecting.png", "PeerToPeerBaseProxy/icons/peer_online.png", "PeerToPeerBaseProxy/icons/peer_error.png")]
     33    [PluginInfo(false, "P2P_Peer_Proxy",
     34        "Creates a new Peer. Uses the CrypTool2 built-in P2P network and can be used as a replacement for P2P_Peer.", ""
     35        , "PeerToPeerBaseProxy/icons/peer_inactive.png", "PeerToPeerBaseProxy/icons/peer_connecting.png",
     36        "PeerToPeerBaseProxy/icons/peer_online.png", "PeerToPeerBaseProxy/icons/peer_error.png")]
    3537    public class P2PPeer : IIOMisc
    3638    {
     39        #region IIOMisc Members
     40
     41        public event GuiLogNotificationEventHandler OnGuiLogNotificationOccured;
     42
     43        public event PluginProgressChangedEventHandler OnPluginProgressChanged;
     44
     45        public event PropertyChangedEventHandler PropertyChanged;
     46
     47        #endregion
     48
    3749        // to forward event from overlay/dht MessageReceived-Event from P2PBase
    3850        public event P2PBase.P2PMessageReceived OnPeerMessageReceived;
    3951
     52        public void OnPropertyChanged(string name)
     53        {
     54            EventsHelper.PropertyChanged(PropertyChanged, this, new PropertyChangedEventArgs(name));
     55        }
     56
     57        private void GuiLogMessage(string p, NotificationLevel notificationLevel)
     58        {
     59            // for evaluation issues only
     60            EventsHelper.GuiLogMessage(OnGuiLogNotificationOccured, this,
     61                                       new GuiLogEventArgs(p + "(" + DebugToFile.GetTimeStamp() + ")", this,
     62                                                           notificationLevel));
     63            //EventsHelper.GuiLogMessage(OnGuiLogNotificationOccured, this, new GuiLogEventArgs(p, this, notificationLevel));
     64        }
     65
     66        public void LogInternalState()
     67        {
     68            P2PManager.Instance.P2PBase.LogInternalState();
     69        }
     70
     71        #region In and Output
     72
     73        [PropertyInfo(Direction.ControlSlave, "Master Peer", "One peer to rule them all", "", true, false,
     74            DisplayLevel.Beginner, QuickWatchFormat.Text, null)]
     75        public IP2PControl P2PControlSlave
     76        {
     77            get { return _p2PSlave ?? (_p2PSlave = new P2PPeerMaster(this)); }
     78        }
     79
     80        #endregion
     81
     82        #region Start and Stop Peer
     83
     84        /// <summary>
     85        /// Status flag for starting and stopping peer only once.
     86        /// </summary>
     87        public bool PeerStarted()
     88        {
     89            return P2PManager.Instance.P2PConnected();
     90        }
     91
     92        public void StartPeer()
     93        {
     94            _settings.PeerStatusChanged(P2PPeerSettings.PeerStatus.Connecting);
     95            P2PManager.Instance.P2PBase.OnP2PMessageReceived += P2PBaseOnP2PMessageReceived;
     96
     97            if (P2PManager.Instance.P2PConnected())
     98            {
     99                GuiLogMessage("P2P connected.", NotificationLevel.Info);
     100                _settings.PeerStatusChanged(P2PPeerSettings.PeerStatus.Online);
     101            }
     102            else
     103            {
     104                GuiLogMessage("P2P network must be configured and connecting using the world button.",
     105                              NotificationLevel.Error);
     106                _settings.PeerStatusChanged(P2PPeerSettings.PeerStatus.Error);
     107            }
     108        }
     109
     110        public void StopPeer()
     111        {
     112            GuiLogMessage("Peer cannot be stopped, it is running in CrypTool!", NotificationLevel.Info);
     113        }
     114
     115        #endregion Start and Stop Peer
     116
    40117        #region Variables
    41118
    42         private P2PPeerSettings settings;
    43         private IP2PControl p2pSlave;
     119        private IP2PControl _p2PSlave;
     120        private P2PPeerSettings _settings;
    44121
    45122        #endregion
     
    49126        public P2PPeer()
    50127        {
    51             this.settings = new P2PPeerSettings(this);
    52             this.settings.TaskPaneAttributeChanged += new TaskPaneAttributeChangedHandler(settings_TaskPaneAttributeChanged);
    53             this.settings.OnPluginStatusChanged += new StatusChangedEventHandler(settings_OnPluginStatusChanged);
     128            _settings = new P2PPeerSettings(this);
     129            _settings.TaskPaneAttributeChanged += SettingsTaskPaneAttributeChanged;
     130            _settings.OnPluginStatusChanged += SettingsOnPluginStatusChanged;
    54131        }
    55132
    56133        public event StatusChangedEventHandler OnPluginStatusChanged;
    57         private void settings_OnPluginStatusChanged(IPlugin sender, StatusEventArgs args)
    58         {
    59             if (OnPluginStatusChanged != null)
    60                 OnPluginStatusChanged(this, args);
    61         }
    62 
    63         // to forward event from overlay/dht MessageReceived-Event from P2PBase
    64         private void p2pBase_OnP2PMessageReceived(PeerId sourceAddr, byte[] data)
    65         {
    66             if (OnPeerMessageReceived != null)
    67                 OnPeerMessageReceived(sourceAddr, data);
    68         }
    69 
    70         void settings_TaskPaneAttributeChanged(ISettings settings, TaskPaneAttributeChangedEventArgs args)
    71         {
    72             //throw new NotImplementedException();
    73         }
    74134
    75135        public ISettings Settings
    76136        {
    77             set { this.settings = (P2PPeerSettings)value; }
    78             get { return this.settings; }
    79         }
    80 
    81         public System.Windows.Controls.UserControl Presentation
     137            set { _settings = (P2PPeerSettings) value; }
     138            get { return _settings; }
     139        }
     140
     141        public UserControl Presentation
    82142        {
    83143            get { return null; }
    84144        }
    85145
    86         public System.Windows.Controls.UserControl QuickWatchPresentation
     146        public UserControl QuickWatchPresentation
    87147        {
    88148            get { return null; }
     
    122182        }
    123183
    124         #endregion
    125 
    126         #region IPlugin Members
    127 
    128         public event GuiLogNotificationEventHandler OnGuiLogNotificationOccured;
    129 
    130         public event PluginProgressChangedEventHandler OnPluginProgressChanged;
    131 
    132         #endregion
    133 
    134         #region INotifyPropertyChanged Members
    135 
    136         public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
    137 
    138         public void OnPropertyChanged(string name)
    139         {
    140             EventsHelper.PropertyChanged(PropertyChanged, this, new PropertyChangedEventArgs(name));
    141         }
    142 
    143         public event PluginProgressChangedEventHandler OnPluginProcessChanged;
    144 
    145         private void ProgressChanged(double value, double max)
    146         {
    147             EventsHelper.ProgressChanged(OnPluginProgressChanged, this, new PluginProgressEventArgs(value, max));
    148         }
    149 
    150         private void GuiLogMessage(string p, NotificationLevel notificationLevel)
    151         {
    152             // for evaluation issues only
    153             EventsHelper.GuiLogMessage(OnGuiLogNotificationOccured, this, new GuiLogEventArgs(p + "(" + DebugToFile.GetTimeStamp() + ")", this, notificationLevel));
    154             //EventsHelper.GuiLogMessage(OnGuiLogNotificationOccured, this, new GuiLogEventArgs(p, this, notificationLevel));
    155         }
    156 
    157         #endregion
    158 
    159         #region In and Output
    160 
    161         [PropertyInfo(Direction.ControlSlave, "Master Peer", "One peer to rule them all", "", true, false, DisplayLevel.Beginner, QuickWatchFormat.Text, null)]
    162         public IP2PControl P2PControlSlave
    163         {
    164             get
    165             {
    166                 if (this.p2pSlave == null)
    167                     // to commit the settings of the plugin to the IControl
    168                     this.p2pSlave = new P2PPeerMaster(this);
    169                 return this.p2pSlave;
    170             }
    171         }
    172 
    173         #endregion
    174 
    175         #region Start and Stop Peer
    176         /// <summary>
    177         /// Status flag for starting and stopping peer only once.
    178         /// </summary>
    179         public bool PeerStarted()
    180         {
    181             return P2PManager.Instance.P2PConnected();
    182         }
    183 
    184         public void StartPeer()
    185         {
    186             this.settings.PeerStatusChanged(P2PPeerSettings.PeerStatus.Connecting);
    187             P2PManager.Instance.P2PBase.OnP2PMessageReceived += new P2PBase.P2PMessageReceived(p2pBase_OnP2PMessageReceived);
    188 
    189             if (P2PManager.Instance.P2PConnected())
    190             {
    191                 GuiLogMessage("P2P connected.", NotificationLevel.Info);
    192                 this.settings.PeerStatusChanged(P2PPeerSettings.PeerStatus.Online);
    193             }
    194             else
    195             {
    196                 GuiLogMessage("P2P network must be configured and connecting using the world button.", NotificationLevel.Error);
    197                 this.settings.PeerStatusChanged(P2PPeerSettings.PeerStatus.Error);
    198             }
    199         }
    200 
    201         public void StopPeer()
    202         {
    203 
    204             GuiLogMessage("Peer cannot be stopped, it is running in CrypTool!", NotificationLevel.Info);
    205         }
    206         #endregion Start and Stop Peer
    207 
    208         public void LogInternalState()
    209         {
    210             P2PManager.Instance.P2PBase.LogInternalState();
    211         }
     184        private void SettingsOnPluginStatusChanged(IPlugin sender, StatusEventArgs args)
     185        {
     186            if (OnPluginStatusChanged != null)
     187                OnPluginStatusChanged(this, args);
     188        }
     189
     190        // to forward event from overlay/dht MessageReceived-Event from P2PBase
     191        private void P2PBaseOnP2PMessageReceived(PeerId sourceAddr, byte[] data)
     192        {
     193            if (OnPeerMessageReceived != null)
     194                OnPeerMessageReceived(sourceAddr, data);
     195        }
     196
     197        private static void SettingsTaskPaneAttributeChanged(ISettings settings, TaskPaneAttributeChangedEventArgs args)
     198        {
     199            //throw new NotImplementedException();
     200        }
     201
     202        #endregion
    212203    }
    213204
     
    215206    public class P2PPeerMaster : IP2PControl
    216207    {
    217         private AutoResetEvent systemJoined;
    218         private P2PPeer p2pPeer;
    219         private PeerId peerID;
    220         private string sPeerName;
     208        private readonly Encoding _enc = Encoding.UTF8;
     209        private readonly P2PPeer _p2PPeer;
     210        private readonly AutoResetEvent _systemJoined;
     211        private PeerId _peerId;
     212        private string _sPeerName;
    221213        // used for every encoding stuff
    222         private Encoding enc = UTF8Encoding.UTF8;
    223 
    224         public P2PPeerMaster(P2PPeer p2pPeer)
    225         {
    226             this.p2pPeer = p2pPeer;
    227             this.systemJoined = new AutoResetEvent(false);
    228 
    229             P2PManager.Instance.P2PBase.OnSystemJoined += new P2PBase.SystemJoined(p2pBase_OnSystemJoined);
    230             P2PManager.Instance.OnPeerMessageReceived += new P2PBase.P2PMessageReceived(p2pPeer_OnPeerMessageReceived);
    231             this.OnStatusChanged += new IControlStatusChangedEventHandler(P2PPeerMaster_OnStatusChanged);
     214
     215        public P2PPeerMaster(P2PPeer p2PPeer)
     216        {
     217            _p2PPeer = p2PPeer;
     218            _systemJoined = new AutoResetEvent(false);
     219
     220            P2PManager.Instance.P2PBase.OnSystemJoined += P2PBaseOnSystemJoined;
     221            P2PManager.Instance.OnPeerMessageReceived += P2PPeerOnPeerMessageReceived;
     222            OnStatusChanged += P2PPeerMaster_OnStatusChanged;
    232223        }
    233224
    234225        #region Events and Event-Handling
    235        
    236         private void p2pBase_OnSystemJoined()
    237         {
    238             systemJoined.Set();
    239         }
    240226
    241227        // to forward event from overlay MessageReceived-Event from P2PBase
     
    243229        public event P2PPayloadMessageReceived OnPayloadMessageReceived;
    244230        public event P2PSystemMessageReceived OnSystemMessageReceived;
    245         private void p2pPeer_OnPeerMessageReceived(PeerId sourceAddr, byte[] data)
     231
     232        public event IControlStatusChangedEventHandler OnStatusChanged;
     233
     234        private void P2PBaseOnSystemJoined()
     235        {
     236            _systemJoined.Set();
     237        }
     238
     239        private void P2PPeerOnPeerMessageReceived(PeerId sourceAddr, byte[] data)
    246240        {
    247241            switch (GetMessageType(data[0])) //analyses the first byte of data (index, which represents the MessageType)
     
    250244                    if (data.Length == 2)
    251245                    {
    252                         if(OnSystemMessageReceived != null)
     246                        if (OnSystemMessageReceived != null)
    253247                            OnSystemMessageReceived(sourceAddr, GetPubSubType(data[1]));
    254248                    }
    255249                    else
    256250                    {
    257                         throw (new Exception("Data seems to be from type 'PubSub', but is to long for it... Data: '" + enc.GetString(data) + "'"));
     251                        throw (new Exception("Data seems to be from type 'PubSub', but is to long for it... Data: '" +
     252                                             _enc.GetString(data) + "'"));
    258253                    }
    259254                    break;
    260255                case P2PMessageIndex.Payload:
    261                     if(OnPayloadMessageReceived != null)
     256                    if (OnPayloadMessageReceived != null)
    262257                        OnPayloadMessageReceived(sourceAddr, GetMessagePayload(data));
    263258                    break;
     
    268263        }
    269264
    270         public event IControlStatusChangedEventHandler OnStatusChanged;
    271265        private void P2PPeerMaster_OnStatusChanged(IControl sender, bool readyForExecution)
    272266        {
     
    277271        #endregion
    278272
     273        #region IP2PControl Members
     274
    279275        public bool PeerStarted()
    280276        {
    281             return this.p2pPeer.PeerStarted();
    282         }
    283 
    284         /// <summary>
    285         /// workaround method. If the PAP functions are used, but the PAP system isn't
    286         /// started yet. This could happen because of the plugin hierarchy and
    287         /// when a p2p-using plugin uses PAP functions in the PreExecution method,
    288         /// this could run into a race condition (peer plugin not computed by the CT-system
    289         /// yet, but p2p-using plugin is already executed)
    290         /// </summary>
    291         /// <returns></returns>
    292         private bool SystemJoinedCompletely()
    293         {
    294             return P2PManager.Instance.P2PConnected();
    295         }
    296 
    297         #region IP2PControl Members
     277            return _p2PPeer.PeerStarted();
     278        }
    298279
    299280        public bool DHTstore(string sKey, byte[] byteValue)
     
    334315            if (SystemJoinedCompletely())
    335316            {
    336                 if (this.peerID == null)
     317                if (_peerId == null)
    337318                {
    338                     this.peerID = P2PManager.Instance.P2PBase.GetPeerID(out this.sPeerName);
     319                    _peerId = P2PManager.Instance.P2PBase.GetPeerID(out _sPeerName);
    339320                }
    340                 sPeerName = this.sPeerName;
    341                 return this.peerID;
     321                sPeerName = _sPeerName;
     322                return _peerId;
    342323            }
    343             sPeerName = this.sPeerName;
     324            sPeerName = _sPeerName;
    344325            return null;
    345326        }
     
    348329        {
    349330            return P2PManager.Instance.P2PBase.GetPeerID(byteId);
    350         }
    351 
    352         private void SendReadilyMessage(byte[] data, PeerId destinationAddress)
    353         {
    354             if (SystemJoinedCompletely())
    355                 P2PManager.Instance.P2PBase.SendToPeer(data, destinationAddress.ToByteArray());
    356331        }
    357332
     
    368343            SendReadilyMessage(data, destinationAddress);
    369344        }
     345
    370346        public void SendToPeer(PubSubMessageType msgType, PeerId destinationAddress)
    371347        {
     
    373349            SendReadilyMessage(data, destinationAddress);
    374350        }
     351
     352        #endregion
    375353
    376354        #region Communication protocol
     
    382360        /// <param name="msgIndex">type of message (system message, simple payload for a special use case, etc.)</param>
    383361        /// <returns>the message, which is processable by the ct2/p2p system</returns>
    384         private byte[] GenerateMessage(byte[] payload, P2PMessageIndex msgIndex)
     362        private static byte[] GenerateMessage(byte[] payload, P2PMessageIndex msgIndex)
    385363        {
    386364            // first byte is the index, if it is payload or Publish/Subscriber stuff
    387             byte[] retByte = new byte[1 + payload.Length];
    388             retByte[0] = (byte)msgIndex;
     365            var retByte = new byte[1 + payload.Length];
     366            retByte[0] = (byte) msgIndex;
    389367            payload.CopyTo(retByte, 1);
    390368            return retByte;
     
    399377        private byte[] GenerateMessage(string sPayload, P2PMessageIndex msgIndex)
    400378        {
    401             return GenerateMessage(enc.GetBytes(sPayload), msgIndex);
     379            return GenerateMessage(_enc.GetBytes(sPayload), msgIndex);
    402380        }
    403381
     
    406384        /// </summary>
    407385        /// <param name="pubSubData">PubSubMessageType</param>
    408         /// <returns>the message, which is processable by the ct2/p2p system<</returns>
    409         private byte[] GenerateMessage(PubSubMessageType pubSubData)
    410         {
    411             byte[] bytePubSubData = new byte[] { (byte)pubSubData };
     386        /// <returns>the message, which is processable by the ct2/p2p system</returns>
     387        private static byte[] GenerateMessage(PubSubMessageType pubSubData)
     388        {
     389            var bytePubSubData = new[] {(byte) pubSubData};
    412390            return GenerateMessage(bytePubSubData, P2PMessageIndex.PubSub);
    413391        }
     
    418396        /// <param name="msgType">the FIRST byte of a raw message, received by the system</param>
    419397        /// <returns>the message type</returns>
    420         private P2PMessageIndex GetMessageType(byte msgType)
    421         {
    422             try
    423             {
    424                 return (P2PMessageIndex)msgType;
    425             }
    426             catch (Exception ex)
    427             {
    428                 throw (ex);
    429             }
    430         }
    431 
    432         /// <summary>
    433         /// returns the message type, e.g. PubSub or Payload message (to accelarate this process, only assign first byte of the whole array message)
    434         /// </summary>
    435         /// <param name="message">the whole message as an byte array</param>
    436         /// <returns>the message type</returns>
    437         private P2PMessageIndex GetMessageType(byte[] message)
    438         {
    439             try
    440             {
    441                 return (P2PMessageIndex)message[0];
    442             }
    443             catch (Exception ex)
    444             {
    445                 throw (ex);
    446             }
     398        private static P2PMessageIndex GetMessageType(byte msgType)
     399        {
     400            return (P2PMessageIndex) msgType;
    447401        }
    448402
     
    452406        /// <param name="message">the raw message, received by the system, as an byte array (with the first index byte!!!)</param>
    453407        /// <returns>only the payload part of the message</returns>
    454         private byte[] GetMessagePayload(byte[] message)
     408        private static byte[] GetMessagePayload(byte[] message)
    455409        {
    456410            if (message.Length > 1)
    457411            {
    458                 byte[] retMsg = new byte[message.Length - 1];
     412                var retMsg = new byte[message.Length - 1];
    459413                // workaround because CopyTo doesn't work...
    460414                //for (int i = 0; i < message.Length-1; i++)
     
    470424        #endregion
    471425
     426        /// <summary>
     427        /// workaround method. If the PAP functions are used, but the PAP system isn't
     428        /// started yet. This could happen because of the plugin hierarchy and
     429        /// when a p2p-using plugin uses PAP functions in the PreExecution method,
     430        /// this could run into a race condition (peer plugin not computed by the CT-system
     431        /// yet, but p2p-using plugin is already executed)
     432        /// </summary>
     433        /// <returns></returns>
     434        private static bool SystemJoinedCompletely()
     435        {
     436            return P2PManager.Instance.P2PConnected();
     437        }
     438
     439        private static void SendReadilyMessage(byte[] data, PeerId destinationAddress)
     440        {
     441            if (SystemJoinedCompletely())
     442                P2PManager.Instance.P2PBase.SendToPeer(data, destinationAddress.ToByteArray());
     443        }
    472444
    473445        /// <summary>
    474446        /// Converts a string to the PubSubMessageType if possible. Otherwise return null.
    475447        /// </summary>
    476         /// <param name="sData">Data</param>
     448        /// <param name="data">Data</param>
    477449        /// <returns>PubSubMessageType if possible. Otherwise null.</returns>
    478         private PubSubMessageType GetPubSubType(byte data)
     450        private static PubSubMessageType GetPubSubType(byte data)
    479451        {
    480452            // Convert one byte data to PublishSubscribeMessageType-Enum
    481             try
    482             {
    483                 return (PubSubMessageType)data;
    484             }
    485             catch (Exception ex)
    486             {
    487                 throw(ex);
    488             }
    489         }
    490 
    491         #endregion
     453            return (PubSubMessageType) data;
     454        }
    492455    }
    493456}
  • trunk/CrypPlugins/PeerToPeerBaseProxy/P2PPeerSettings.cs

    r1438 r1458  
    1 using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
     1using System.ComponentModel;
     2using System.Windows;
    53using Cryptool.PluginBase;
    6 using System.ComponentModel;
    7 using Cryptool.PluginBase.Control;
    8 using System.Windows;
    9 using Cryptool.Plugins.PeerToPeer.Internal;
    10 using Cryptool.Plugins.PeerToPeer;
    114
    125namespace Cryptool.Plugins.PeerToPeerProxy
    136{
    14     class P2PPeerSettings : ISettings
     7    internal class P2PPeerSettings : ISettings
    158    {
    16         public event TaskPaneAttributeChangedHandler TaskPaneAttributeChanged;
    17         public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
     9        #region PeerStatus enum
    1810
    19         private bool hasChanges = false;
    20         private P2PPeer p2pPeer;
     11        public enum PeerStatus
     12        {
     13            NotConnected = 0,
     14            Connecting = 1,
     15            Online = 2,
     16            Error = 3
     17        }
     18
     19        #endregion
     20
     21        private readonly P2PPeer p2pPeer;
    2122
    2223        #region ISettings Members
    2324
    24         public bool HasChanges
    25         {
    26             get
    27             {
    28                 return hasChanges;
    29             }
    30             set
    31             {
    32                 hasChanges = value;
    33             }
    34         }
     25        public event PropertyChangedEventHandler PropertyChanged;
     26
     27        public bool HasChanges { get; set; }
    3528
    3629        #endregion
     
    3831        #region taskPane
    3932
    40         public P2PPeerSettings (P2PPeer p2pPeer)
    41             {
    42             if(TaskPaneAttributeChanged != null)
    43                 TaskPaneAttributeChanged(this, new TaskPaneAttributeChangedEventArgs(new TaskPaneAttribteContainer("BtnStop", Visibility.Hidden)));
     33        public P2PPeerSettings(P2PPeer p2pPeer)
     34        {
     35            if (TaskPaneAttributeChanged != null)
     36                TaskPaneAttributeChanged(this,
     37                                         new TaskPaneAttributeChangedEventArgs(new TaskPaneAttribteContainer("BtnStop",
     38                                                                                                             Visibility.
     39                                                                                                                 Hidden)));
    4440            this.p2pPeer = p2pPeer;
    4541            ChangePluginIcon(PeerStatus.NotConnected);
    46             }
     42        }
    4743
    4844        #endregion
     
    5046        #region Start- and Stop-Buttons incl. functionality
    5147
    52         [TaskPane("Internal state dump", "Dumps the interla state of the P2P system to syslog.", "P2P Expert Settings", 0, true, DisplayLevel.Beginner, ControlType.Button)]
     48        [TaskPane("Internal state dump", "Dumps the interla state of the P2P system to syslog.", "P2P Expert Settings",
     49            0, true, DisplayLevel.Beginner, ControlType.Button)]
    5350        public void BtnLogInternalState()
    5451        {
    55             this.p2pPeer.LogInternalState();
     52            p2pPeer.LogInternalState();
    5653        }
    5754
    5855        #endregion
    5956
    60         #region INotifyPropertyChanged Members
     57        public event TaskPaneAttributeChangedHandler TaskPaneAttributeChanged;
    6158
    6259        private void OnPropertyChanged(string p)
     
    6865        }
    6966
    70         #endregion
    71 
    7267        // Index depends on icon-position in P2PPeer-Class properties
    73         public enum PeerStatus
    74         {
    75             NotConnected = 0,
    76             Connecting = 1,
    77             Online = 2,
    78             Error = 3
    79         }
    8068
    8169        /// <summary>
     
    9179                case PeerStatus.Online:
    9280                    TaskPaneAttributeChanged(this, new TaskPaneAttributeChangedEventArgs(
    93                         new TaskPaneAttribteContainer("BtnStart", Visibility.Collapsed)));
     81                                                       new TaskPaneAttribteContainer("BtnStart", Visibility.Collapsed)));
    9482                    TaskPaneAttributeChanged(this, new TaskPaneAttributeChangedEventArgs(
    95                         new TaskPaneAttribteContainer("BtnStop", Visibility.Visible)));
     83                                                       new TaskPaneAttribteContainer("BtnStop", Visibility.Visible)));
    9684                    break;
    9785                case PeerStatus.NotConnected:
    9886                    TaskPaneAttributeChanged(this, new TaskPaneAttributeChangedEventArgs(
    99                         new TaskPaneAttribteContainer("BtnStart", Visibility.Visible)));
     87                                                       new TaskPaneAttribteContainer("BtnStart", Visibility.Visible)));
    10088                    TaskPaneAttributeChanged(this, new TaskPaneAttributeChangedEventArgs(
    101                         new TaskPaneAttribteContainer("BtnStop", Visibility.Hidden)));
     89                                                       new TaskPaneAttribteContainer("BtnStop", Visibility.Hidden)));
    10290                    break;
    10391                case PeerStatus.Error:
     
    10997
    11098        public event StatusChangedEventHandler OnPluginStatusChanged;
     99
    111100        private void ChangePluginIcon(PeerStatus peerStatus)
    112101        {
    113             if (OnPluginStatusChanged != null) 
    114                 OnPluginStatusChanged(null, new StatusEventArgs(StatusChangedMode.ImageUpdate, (int)peerStatus));
     102            if (OnPluginStatusChanged != null)
     103                OnPluginStatusChanged(null, new StatusEventArgs(StatusChangedMode.ImageUpdate, (int) peerStatus));
    115104        }
    116105    }
  • trunk/CrypPlugins/PeerToPeerBaseProxy/PeerToPeerBaseProxy.csproj

    r1451 r1458  
    99    <OutputType>Library</OutputType>
    1010    <AppDesignerFolder>Properties</AppDesignerFolder>
    11     <RootNamespace>Cryptool.Plugins.PeerToPeer</RootNamespace>
     11    <RootNamespace>Cryptool.Plugins.PeerToPeerProxy</RootNamespace>
    1212    <AssemblyName>PeerToPeerBaseProxy</AssemblyName>
    1313    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
     
    8989  </PropertyGroup>
    9090  <ItemGroup>
    91     <Reference Include="Bootstrapper, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
    92       <SpecificVersion>False</SpecificVersion>
    93       <HintPath>..\..\AppReferences\Bootstrapper.dll</HintPath>
    94     </Reference>
    95     <Reference Include="CertServices, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
    96       <SpecificVersion>False</SpecificVersion>
    97       <HintPath>..\..\AppReferences\CertServices.dll</HintPath>
    98     </Reference>
    99     <Reference Include="FullMeshDHT, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
    100       <SpecificVersion>False</SpecificVersion>
    101       <HintPath>..\..\AppReferences\FullMeshDHT.dll</HintPath>
    102     </Reference>
    103     <Reference Include="FullMeshOverlay, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
    104       <SpecificVersion>False</SpecificVersion>
    105       <HintPath>..\..\AppReferences\FullMeshOverlay.dll</HintPath>
    106     </Reference>
    107     <Reference Include="Gears4Net, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
    108       <SpecificVersion>False</SpecificVersion>
    109       <HintPath>..\..\AppReferences\Gears4Net.dll</HintPath>
    110     </Reference>
    111     <Reference Include="LinkManager, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
    112       <SpecificVersion>False</SpecificVersion>
    113       <HintPath>..\..\AppReferences\LinkManager.dll</HintPath>
    114     </Reference>
    115     <Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=c2ce2cb84dc7c251, processorArchitecture=MSIL">
    116       <SpecificVersion>False</SpecificVersion>
    117       <HintPath>..\..\AppReferences\log4net.dll</HintPath>
    118     </Reference>
    119     <Reference Include="NetGearsTCP, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
    120       <SpecificVersion>False</SpecificVersion>
    121       <HintPath>..\..\AppReferences\NetGearsTCP.dll</HintPath>
    122     </Reference>
    123     <Reference Include="PeersAtPlayBase, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
    124       <SpecificVersion>False</SpecificVersion>
    125       <HintPath>..\..\AppReferences\PeersAtPlayBase.dll</HintPath>
    126     </Reference>
    12791    <Reference Include="PresentationCore" />
    12892    <Reference Include="PresentationFramework" />
    129     <Reference Include="RUDP, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
    130       <SpecificVersion>False</SpecificVersion>
    131       <HintPath>..\..\AppReferences\RUDP.dll</HintPath>
    132     </Reference>
    133     <Reference Include="Stun, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
    134       <SpecificVersion>False</SpecificVersion>
    135       <HintPath>..\..\AppReferences\Stun.dll</HintPath>
    136     </Reference>
    13793    <Reference Include="System" />
    138     <Reference Include="System.Core" />
    13994    <Reference Include="System.Xaml" />
    140     <Reference Include="System.Xml.Linq" />
    141     <Reference Include="System.Data.DataSetExtensions" />
    142     <Reference Include="System.Data" />
    143     <Reference Include="System.Xml" />
    144     <Reference Include="Util, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
    145       <SpecificVersion>False</SpecificVersion>
    146       <HintPath>..\..\AppReferences\Util.dll</HintPath>
    147     </Reference>
    14895    <Reference Include="WindowsBase" />
    14996  </ItemGroup>
     
    174121      <Name>CrypPluginBase</Name>
    175122    </ProjectReference>
    176     <ProjectReference Include="..\PeerToPeerCertificates\PeerToPeerCertificates.csproj">
    177       <Project>{7BED5C93-30BE-47BE-BC4A-16453F5DE9EA}</Project>
    178       <Name>PeerToPeerCertificates</Name>
    179     </ProjectReference>
    180123    <ProjectReference Include="..\PeerToPeer\PeerToPeer.csproj">
    181124      <Project>{12829116-8FAD-4D09-A0AA-D75D88F07626}</Project>
Note: See TracChangeset for help on using the changeset viewer.