Changeset 1066


Ignore:
Timestamp:
Jan 12, 2010, 11:50:43 AM (12 years ago)
Author:
arnold
Message:

New DLLs integrated and radical changes in the DHT functionality (DHT versioning system disabled, new DHTRemove, etc.)

The lib is required by all developers, so I'm adding it explicitly to the repository.

override-bad-extension: Bootstrapper.dll
override-bad-extension: Bootstrapper.pdb
override-bad-extension: CertServices.dll
override-bad-extension: CertServices.pdb
override-bad-extension: FullMeshDHT.dll
override-bad-extension: FullMeshDHT.pdb
override-bad-extension: FullMeshOverlay.dll
override-bad-extension: FullMeshOverlay.pdb
override-bad-extension: Gears4Net.dll
override-bad-extension: Gears4Net.pdb
override-bad-extension: NetGearsTCP.dll
override-bad-extension: NetGearsTCP.pdb
override-bad-extension: PeersAtPlayBase.dll
override-bad-extension: PeersAtPlayBase.pdb
override-bad-extension: SimpleSnalNG.dll
override-bad-extension: SimpleSnalNG.pdb
override-bad-extension: Stun.dll
override-bad-extension: Stun.pdb
override-bad-extension: Util.dll
override-bad-extension: Util.pdb

Location:
trunk/CrypPlugins/PeerToPeerBase
Files:
8 added
4 deleted
35 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/PeerToPeerBase/IP2PControl.cs

    r1022 r1066  
    3030
    3131    /// <summary>
    32     /// Message types for Publish/Subscriber systems
     32    /// Message types for maintaining the Publish/Subscriber systems
    3333    /// </summary>
    3434    public enum PubSubMessageType
     
    7474        NULL = 666
    7575    }
     76
     77    /// <summary>
     78    /// necessary index for all p2p messages, which have to be processed by ct2
     79    /// </summary>
     80    public enum P2PMessageIndex
     81    {
     82        /// <summary>
     83        /// indicates, that a PubSubMessageType will follow
     84        /// </summary>
     85        PubSub = 0,
     86        /// <summary>
     87        /// indicates, that any kind of payload data will follow
     88        /// </summary>
     89        Payload = 1
     90    }
    7691    #endregion
     92
     93    public delegate void P2PPayloadMessageReceived(PeerId sender, byte[] data);
     94    public delegate void P2PSystemMessageReceived(PeerId sender, PubSubMessageType msgType);
    7795
    7896    public interface IP2PControl : IControl
    7997    {
     98        //event P2PBase.P2PMessageReceived OnPeerReceivedMsg;
     99        event P2PPayloadMessageReceived OnPayloadMessageReceived;
     100        event P2PSystemMessageReceived OnSystemMessageReceived;
     101
    80102        bool DHTstore(string sKey, byte[] byteValue);
    81103        bool DHTstore(string sKey, string sValue);
     
    88110        PeerId GetPeerID(byte[] byteId);
    89111
     112        /// <summary>
     113        /// Sends data to the specified peer
     114        /// </summary>
     115        /// <param name="data">only send PAYLOAD data as an byte-array (attention:
     116        /// don't add an index by yourselve, index will be added internally)</param>
     117        /// <param name="destinationAddress">the address of the destination peer</param>
     118        void SendToPeer(byte[] data, PeerId destinationAddress);
     119        /// <summary>
     120        /// Sends data to the specified peer
     121        /// </summary>
     122        /// <param name="sData">only send PAYLOAD data as a string</param>
     123        /// <param name="destinationAddress">the address of the destination peer</param>
    90124        void SendToPeer(string sData, PeerId destinationAddress);
    91         //void SendToPeer(string sData, byte[] sDestinationPeerAddress);
    92         //void SendToPeer(string sData, string sDestinationPeerAddress);
     125        /// <summary>
     126        /// Sends data to the specified peer
     127        /// </summary>
     128        /// <param name="msgType">a PubSub-System message</param>
     129        /// <param name="sDestinationAddress">the address of the destination peer</param>
    93130        void SendToPeer(PubSubMessageType msgType, PeerId sDestinationAddress);
    94         void SendToPeer(string sData, byte[] destinationAddress);
    95         //void SendToPeer(PubSubMessageType msgType, string sDestinationAddress);
    96 
    97         PubSubMessageType GetMsgType(string byteData);
    98 
    99         event P2PBase.P2PMessageReceived OnPeerReceivedMsg;
    100131    }
    101132}
  • trunk/CrypPlugins/PeerToPeerBase/P2PPeer.cs

    r1022 r1066  
    6666
    6767        // to forward event from overlay/dht MessageReceived-Event from P2PBase
    68         private void p2pBase_OnP2PMessageReceived(PeerId sourceAddr, string sData)
     68        private void p2pBase_OnP2PMessageReceived(PeerId sourceAddr, byte[] data)
    6969        {
    7070            if (OnPeerMessageReceived != null)
    71                 OnPeerMessageReceived(sourceAddr, sData);
     71                OnPeerMessageReceived(sourceAddr, data);
    7272        }
    7373
     
    272272        private PeerId peerID;
    273273        private string sPeerName;
     274        // used for every encoding stuff
     275        private Encoding enc = UTF8Encoding.UTF8;
    274276
    275277        public P2PPeerMaster(P2PPeer p2pPeer)
     
    290292        }
    291293
    292         // to forward event from overlay/dht MessageReceived-Event from P2PBase
    293         public event P2PBase.P2PMessageReceived OnPeerReceivedMsg;
    294         private void p2pPeer_OnPeerMessageReceived(PeerId sourceAddr, string sData)
    295         {
    296             if (OnPeerReceivedMsg != null)
    297                 OnPeerReceivedMsg(sourceAddr, sData);
     294        // to forward event from overlay MessageReceived-Event from P2PBase
     295        // analyzes the type of message and throws depend upon this anaysis an event
     296        public event P2PPayloadMessageReceived OnPayloadMessageReceived;
     297        public event P2PSystemMessageReceived OnSystemMessageReceived;
     298        private void p2pPeer_OnPeerMessageReceived(PeerId sourceAddr, byte[] data)
     299        {
     300            switch (GetMessageType(data[0])) //analyses the first byte of data (index, which represents the MessageType)
     301            {
     302                case P2PMessageIndex.PubSub:
     303                    if (data.Length == 2)
     304                    {
     305                        if(OnSystemMessageReceived != null)
     306                            OnSystemMessageReceived(sourceAddr, GetPubSubType(data[1]));
     307                    }
     308                    else
     309                    {
     310                        throw (new Exception("Data seems to be from type 'PubSub', but is to long for it... Data: '" + enc.GetString(data) + "'"));
     311                    }
     312                    break;
     313                case P2PMessageIndex.Payload:
     314                    if(OnPayloadMessageReceived != null)
     315                        OnPayloadMessageReceived(sourceAddr, GetMessagePayload(data));
     316                    break;
     317                default:
     318                    // not implemented. System ignores these messages completely at present
     319                    break;
     320            }
    298321        }
    299322
     
    385408        }
    386409
     410        private void SendReadilyMessage(byte[] data, PeerId destinationAddress)
     411        {
     412            if (SystemJoinedCompletely())
     413                this.p2pPeer.p2pBase.SendToPeer(data, destinationAddress.ToByteArray());
     414        }
     415
     416        // adds the P2PMessageIndex to the given byte-array
     417        public void SendToPeer(byte[] data, PeerId destinationAddress)
     418        {
     419            byte[] newData = GenerateMessage(data, P2PMessageIndex.Payload);
     420            SendReadilyMessage(newData, destinationAddress);
     421        }
     422
    387423        public void SendToPeer(string sData, PeerId destinationAddress)
    388424        {
    389             if (SystemJoinedCompletely())
    390                 this.p2pPeer.p2pBase.SendToPeer(sData, destinationAddress);
     425            byte[] data = GenerateMessage(sData, P2PMessageIndex.Payload);
     426            SendReadilyMessage(data, destinationAddress);
    391427        }
    392428        public void SendToPeer(PubSubMessageType msgType, PeerId destinationAddress)
    393429        {
    394             if (SystemJoinedCompletely())
    395                 this.p2pPeer.p2pBase.SendToPeer(msgType, destinationAddress);
    396         }
    397         public void SendToPeer(string sData, byte[] destinationAddress)
    398         {
    399             if (SystemJoinedCompletely())
    400                 this.p2pPeer.p2pBase.SendToPeer(sData, destinationAddress);
    401         }
     430            byte[] data = GenerateMessage(msgType);
     431            SendReadilyMessage(data, destinationAddress);
     432        }
     433
     434        #region Communication protocol
     435
     436        /* TODO:
     437         * - Test this methods
     438         * - Integrate data types of payload
     439         * - Implement deserialize method */
     440
     441        /// <summary>
     442        /// generates a ct2- and p2p-compatible and processable message
     443        /// </summary>
     444        /// <param name="payload">payload data in bytes</param>
     445        /// <param name="msgIndex">type of message (system message, simple payload for a special use case, etc.)</param>
     446        /// <returns>the message, which is processable by the ct2/p2p system</returns>
     447        private byte[] GenerateMessage(byte[] payload, P2PMessageIndex msgIndex)
     448        {
     449            // first byte is the index, if it is payload or Publish/Subscriber stuff
     450            byte[] retByte = new byte[1 + payload.Length];
     451            retByte[0] = (byte)msgIndex;
     452            payload.CopyTo(retByte, 1);
     453            return retByte;
     454        }
     455
     456        /// <summary>
     457        /// generates a ct2- and p2p-compatible and processable message
     458        /// </summary>
     459        /// <param name="sPayload">payload data as a string</param>
     460        /// <param name="msgIndex">type of message (system message, simple payload for a special use case, etc.)</param>
     461        /// <returns>the message, which is processable by the ct2/p2p system</returns>
     462        private byte[] GenerateMessage(string sPayload, P2PMessageIndex msgIndex)
     463        {
     464            return GenerateMessage(enc.GetBytes(sPayload), msgIndex);
     465        }
     466
     467        /// <summary>
     468        /// generates a ct2- and p2p-compatible and processable message
     469        /// </summary>
     470        /// <param name="pubSubData">PubSubMessageType</param>
     471        /// <returns>the message, which is processable by the ct2/p2p system<</returns>
     472        private byte[] GenerateMessage(PubSubMessageType pubSubData)
     473        {
     474            byte[] bytePubSubData = new byte[] { (byte)pubSubData };
     475            return GenerateMessage(bytePubSubData, P2PMessageIndex.PubSub);
     476        }
     477
     478        /// <summary>
     479        /// returns the message type, e.g. PubSub or Payload message
     480        /// </summary>
     481        /// <param name="msgType">the FIRST byte of a raw message, received by the system</param>
     482        /// <returns>the message type</returns>
     483        private P2PMessageIndex GetMessageType(byte msgType)
     484        {
     485            try
     486            {
     487                return (P2PMessageIndex)msgType;
     488            }
     489            catch (Exception ex)
     490            {
     491                throw (ex);
     492            }
     493        }
     494
     495        /// <summary>
     496        /// returns the message type, e.g. PubSub or Payload message (to accelarate this process, only assign first byte of the whole array message)
     497        /// </summary>
     498        /// <param name="message">the whole message as an byte array</param>
     499        /// <returns>the message type</returns>
     500        private P2PMessageIndex GetMessageType(byte[] message)
     501        {
     502            try
     503            {
     504                return (P2PMessageIndex)message[0];
     505            }
     506            catch (Exception ex)
     507            {
     508                throw (ex);
     509            }
     510        }
     511
     512        /// <summary>
     513        /// returns only the payload part of the message
     514        /// </summary>
     515        /// <param name="message">the raw message, received by the system, as an byte array (with the first index byte!!!)</param>
     516        /// <returns>only the payload part of the message</returns>
     517        private byte[] GetMessagePayload(byte[] message)
     518        {
     519            if (message.Length > 1)
     520            {
     521                byte[] retMsg = new byte[message.Length - 1];
     522                // workaround because CopyTo doesn't work...
     523                //for (int i = 0; i < message.Length-1; i++)
     524                //{
     525                //    retMsg[i] = message[i + 1];
     526                //}
     527                Buffer.BlockCopy(message, 1, retMsg, 0, message.Length - 1);
     528                return retMsg;
     529            }
     530            return null;
     531        }
     532
     533        #endregion
     534
    402535
    403536        /// <summary>
     
    406539        /// <param name="sData">Data</param>
    407540        /// <returns>PubSubMessageType if possible. Otherwise null.</returns>
    408         public PubSubMessageType GetMsgType(string sData)
     541        private PubSubMessageType GetPubSubType(byte data)
    409542        {
    410543            // Convert one byte data to PublishSubscribeMessageType-Enum
    411             int iMsg;
    412             if (sData.Trim().Length == 1 && Int32.TryParse(sData.Trim(), out iMsg))
    413             {
    414                 return (PubSubMessageType)iMsg;
    415             }
    416             else
    417             {
    418                 // because Enum is non-nullable, I used this workaround
    419                 return PubSubMessageType.NULL;
     544            try
     545            {
     546                return (PubSubMessageType)data;
     547            }
     548            catch (Exception ex)
     549            {
     550                throw(ex);
    420551            }
    421552        }
  • trunk/CrypPlugins/PeerToPeerBase/PeerToPeerBase.csproj

    r971 r1066  
    4848      <HintPath>dlls\Debug\FullMeshOverlay.dll</HintPath>
    4949    </Reference>
     50    <Reference Include="Gears4Net, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
     51      <SpecificVersion>False</SpecificVersion>
     52      <HintPath>dlls\Debug\Gears4Net.dll</HintPath>
     53    </Reference>
    5054    <Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
    5155      <SpecificVersion>False</SpecificVersion>
    5256      <HintPath>dlls\Debug\log4net.dll</HintPath>
    53     </Reference>
    54     <Reference Include="NetGears, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
    55       <SpecificVersion>False</SpecificVersion>
    56       <HintPath>dlls\Debug\NetGears.dll</HintPath>
    5757    </Reference>
    5858    <Reference Include="NetGearsTCP, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
     
    101101    <Compile Include="DebugToFile.cs" />
    102102    <Compile Include="IP2PControl.cs" />
     103    <Compile Include="KeySearcherResult.cs" />
    103104    <Compile Include="P2PPeerSettings.cs" />
    104105    <Compile Include="P2PPeer.cs" />
     
    111112      <Project>{25DB2B47-A457-4EC2-960B-395CE07AE093}</Project>
    112113      <Name>CrypPluginBase</Name>
     114    </ProjectReference>
     115    <ProjectReference Include="..\KeySearcher\KeySearcher.csproj">
     116      <Project>{0579E099-66B2-43C3-B8A0-43CAE4895E68}</Project>
     117      <Name>KeySearcher</Name>
    113118    </ProjectReference>
    114119  </ItemGroup>
Note: See TracChangeset for help on using the changeset viewer.