gfxgfx
 
Please login or register.

Login with username, password and session length
 
gfx gfx
gfx
76793 Posts in 13502 Topics by 1651 Members - Latest Member: Arnold99 November 21, 2024, 05:50:15 pm
*
gfx*gfx
gfx
WinMX World :: Forum  |  Technical  |  Protocol Discussion  |  How WinMX Gets Primarys To connect to
gfx
gfxgfx
 

Author Topic: How WinMX Gets Primarys To connect to  (Read 3206 times)

0 Members and 1 Guest are viewing this topic.

Offline Josh

  • Forum Member
  • Thinking about tomorrow...
    • http://www.winmxunlimited.net
How WinMX Gets Primarys To connect to
« on: March 05, 2006, 09:25:55 am »
We need this information part for here. How to get Primary's. Using ports 7940-7942
- Josh

Offline String

  • Core
  • *****
    • winmx.p2pforum.it
Re: How WinMX Gets Primarys To connect to
« Reply #1 on: March 09, 2006, 05:15:24 pm »
(The code listed below is VB .NET, taken from WinZO client)


1) HOW TO GET PARENT NODE INFORMATION
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The first thing we have to do is to fill a list with the peer cache address currently availables.

      Dim list3 As New List(Of IPEndPoint)
      list3.Add(New IPEndPoint(IPAddress.Parse("205.238.40.1"), 7950))
      list3.Add(New IPEndPoint(IPAddress.Parse("67.18.233.36"), 7950))
      list3.Add(New IPEndPoint(IPAddress.Parse("82.43.224.20"), 7950))
      list3.Add(New IPEndPoint(IPAddress.Parse("209.67.209.50"), 7950))
      list3.Add(New IPEndPoint(IPAddress.Parse("212.227.64.159"), 7950))


Now, before to connect to one of them, we randomize them in the way showed below.
Of course peercache is a List(Of IPEndPoint)

      Dim enumerator1 As Enumerator(Of IPEndPoint) = SequenceUtils.Shuffle(Of IPEndPoint)(peercache).GetEnumerator

Now we start connecting...

      Do While enumerator1.MoveNext
                  Dim point1 As IPEndPoint = enumerator1.get_Current
                  Dim connection1 As New Connection(LogUtils.Log(Of IPEndPoint)(point1, "CACHE"))
                  Try
                        If Not connection1.Connect Then
                              Continue Do
                        End If
     ....


When we are connected to a peer cache we need to read the 56 value (0x38) as the first byte.

                    If (connection1.Reader.ReadByte <> 56) Then
                          Continue Do
                    End If
      ....


If this is the case,  we then read the next 16 bytes and so we expect to get the right crypt key.
(Refer to the the WinSock.dll library documentation for the GetCryptKeyType function)

           If (WNPNEncryption.GetCryptKeyType(CType(connection1.Reader.ReadBytes(16), Byte())) <> CryptKeyType.NodeList) Then
                  Continue Do
           End If

Just for reference

Public Enum CryptKeyType As Byte
      ChatClient = 87
      ChatServer = 88
      NodeList = 84                  <---- we expect this one (0x54)
      PrimaryClient = 80
      PrimaryServer = 81
      SecondaryClient = 82
      SecondaryServer = 83
End Enum


Now we are ready to get infos about the wpn nodes
So we read a 132 bytes long data packet and use the DecryptFrontCode tables to decrypt it.
(For the DecryptFrontCode function refer to the Winsock library documentation)

         Dim list1 As List(Of NodeInfo) =
         NodeInfo.ExtractNodeInfos(WNPNEncryption.DecryptFrontCode(CType(connection1.Reader.ReadBytes(132), Byte())))

                             
Think about NodeInfo as a struct or just a class.
Through the ExtractNodeinfos method we get all the infos about the node

         Dim info1 As New NodeInfo
         info1.IP = New IPAddress(CType(r.ReadUInt, Long))         (4 bytes)
         info1.UdpPort = r.ReadWord                    (2 bytes)
         info1.TcpPort = r.ReadWord                   (2 bytes)       
         info1.FreePrimary = r.ReadByte                   (1 byte)
         info1.FreeSecondary = r.ReadByte                   (1 byte)
         info1.Reserved = r.ReadWord                       (2 byte)
         info1.LastUpdated = DateTime.Now




2) HOW TO CONNECT TO A WPN PARENT NODE
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

In the NodeInfo data struct (or class) we have the Parent node IP address and the TCP port we need to connect to.
So we start connecting to it...

        Dim connection1 As New Connection(New IPEndPoint(node.IP, node.TcpPort))

When connected we receive a byte (0x31 valued)

        If (connection1.Reader.ReadByte <> 49) Then
               Throw New CantConnectParentNodeException("First byte incorrect")
        End If

Now we are entering a crypted session, so we send a 16 bytes long packet with our crypt key ()

        connection1.Writer.Write(WNPNEncryption.CreateCryptKeyID(CryptKeyType.SecondaryClient))

Next we receive 16 bytes from the node and check it against the right value (0x53)

        If (WNPNEncryption.GetCryptKeyType(buffer1) <> CryptKeyType.SecondaryServer) Then
                 Throw New CantConnectParentNodeException(...})
        End If


So we get the two crypt key we need to encrypt/decrypt all the data packets we send/receive
from this secondary connection server.

        class1.upkey = LogUtils.Log(Of UInt32)(WNPNEncryption.GetCryptKeyUp(buffer1), "UpKey")
        class1.downkey = LogUtils.Log(Of UInt32)(WNPNEncryption.GetCryptKeyDown(buffer1), "DownKey")


Now that we obtained the two crypt key we have to send the login packet, as showed below:

         this.Write(new LoginPacket(this.LoginName + "000", LineType.K64, ListenPort ));
         return SecondaryConnection.State.SentLogin;

By a login packet we mean :
   
         nickname (string) + linetype (byte) + reserved (byte) + port number (2 bytes)

Now we receive the login confirmation and we are able to make our name (look the code below):

      ushort num1 = this.StreamReader.ReadWord();
      ushort num2 = this.StreamReader.ReadWord();
      MyBinaryReader reader1 = new MyBinaryReader(new MemoryStream((byte[]) this.StreamReader.ReadBytes(num2)));
      ushort num3 = num1;
                 
      if (num3 == 0x460)
       {
            this.LoginUserID = LogUtils.Log<ushort>(reader1.ReadWord(), "UserID");
             ...
        }


We are done !  we have established a secondary connection.
The thing we would do now is to send our shared files, but i will not deal with this topic here.

Offline Stevi

  • #1 DJ
  • MX Hosts
  • *****
  • Ooops! I blew up the commercials!
    • WinMX Radio
Re: How WinMX Gets Primarys To connect to
« Reply #2 on: March 09, 2006, 05:56:38 pm »
Very nice response String

I couldnt have said it...lol

Offline Josh

  • Forum Member
  • Thinking about tomorrow...
    • http://www.winmxunlimited.net
Re: How WinMX Gets Primarys To connect to
« Reply #3 on: March 11, 2006, 12:38:49 am »
that looks like a mix of c# and vb.net
- Josh

KM

  • Guest
Re: How WinMX Gets Primarys To connect to
« Reply #4 on: March 11, 2006, 04:13:53 am »
Quote
(The code listed below is VB .NET, taken from WinZO client)

Quote
that looks like a mix of c# and vb.net

...interesting observation, what gives you the idea it might have anything to do with VB.NET? lol

Offline Josh

  • Forum Member
  • Thinking about tomorrow...
    • http://www.winmxunlimited.net
Re: How WinMX Gets Primarys To connect to
« Reply #5 on: March 11, 2006, 05:12:11 am »
well i dont see vb.net having any ";"'s in them!




    ushort num1 = this.StreamReader.ReadWord();
      ushort num2 = this.StreamReader.ReadWord();
      MyBinaryReader reader1 = new MyBinaryReader(new MemoryStream((byte[]) this.StreamReader.ReadBytes(num2)));
      ushort num3 = num1;
                 
      if (num3 == 0x460)
       {
            this.LoginUserID = LogUtils.Log<ushort>(reader1.ReadWord(), "UserID");
             ...
        }
- Josh

Offline GhostShip

  • Ret. WinMX Special Forces
  • WMW Team
  • *****
Re: How WinMX Gets Primarys To connect to
« Reply #6 on: March 11, 2006, 04:43:29 pm »
The code was taken from a C# program that is a similar format to VB.NET, I,m suprised String never noticed this as its quite clearly stated on the Winzo site here

http://away.kiev.ua/?winzo

All the information above is contained in every version of other open src projects like those at Mxcontrol , the only difference is winzo was built as a file shaing client only, I,m suprised no one has added a plugin for Robomx to do the same thing by adding some new routines and the extra packet types and then perhaps a move towards open src MX might one day beome a reality.

For those wishing to look through Winzo for the extra information to add to their protocol list just use this simple tool

http://www.aisto.com/roeder/dotnet/Download.aspx?File=Reflector

Anyway Cheers to String  8)    for taking the time to list all the info out for Josh to see in more detail the parts of winmx's operation he enquired about.


Offline String

  • Core
  • *****
    • winmx.p2pforum.it
Re: How WinMX Gets Primarys To connect to
« Reply #7 on: March 11, 2006, 09:07:23 pm »
If you really want to learn about a new MX Client, have a look here !!!  :wink:

http://xoomer.virgilio.it/lastanzadidaniela/

(Yes, the last two code snippets are C#...all the others should be in the language i promised)

Offline GhostShip

  • Ret. WinMX Special Forces
  • WMW Team
  • *****
Re: How WinMX Gets Primarys To connect to
« Reply #8 on: March 12, 2006, 05:40:23 am »
 :lol:

I think that page makes more sense than some of the latest pop releases  :)

WinMX World :: Forum  |  Technical  |  Protocol Discussion  |  How WinMX Gets Primarys To connect to
 

gfxgfx
gfx
©2005-2024 WinMXWorld.com. All Rights Reserved.
SMF 2.0.19 | SMF © 2021, Simple Machines | Terms and Policies
Page created in 0.009 seconds with 22 queries.
Helios Multi © Bloc
gfx
Powered by MySQL Powered by PHP Valid XHTML 1.0! Valid CSS!