Gnutella Forums  

Go Back   Gnutella Forums > Gnutella News and Gnutelliums Forums > General Gnutella Development Discussion
Register FAQ Members List Calendar Arcade Search Today's Posts Mark Forums Read

General Gnutella Development Discussion For general discussion about Gnutella development.


Welcome To Gnutella Forums

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! (click here)

If you have any problems with the registration process or your account login, please contact contact us. Your email address must be legitimate and verified before becoming a full member of the forums. Please be sure to disable any spam filters you may have for our website, so that email messages can reach you.

Once registered but before posting, members MUST READ the FORUM RULES (click here) and LimeWire/FrostWire users should include System details - help us to help you (click on blue link) in their posts if their problem relates to using the program. Whilst forum helpers are happy to help where they can, without these system details your post might be ignored. And wise to read How to create a New Thread

Thank you
Deutsch? Español? Français? Nederlands?
Hilfe in Deutsch, Ayuda en español, Aide en français, Hulp in het Nederlands

Forum Rules

Support Forums

Before you post to one of the specific Client Help and Support Conferences in Gnutella Client Forums please look through other threads and Stickies that may answer your questions. Most problems are not new. The Search function is most useful. Also the red Stickies have answers to the most commonly asked questions. (over 90 percent).
If your problem is not resolved by a search of the forums, please take the next step and post in the appropriate forum. There are many members who will be glad to help.
If you are new to the world of file sharing please do not be shy! Everyone was ‘new’ when they first started.

When posting, please include details for:
Your Operating System ....... Your version of your Gnutella Client ....... Your Internet connection (56K, Cable, DSL) ....... The exact error message, if one pops up
Any other relevant information that you think may help ....... Try to make your post descriptive, specific, and clear so members can quickly and efficiently help you
LimeWire and FrostWire users need to supply these details >>> System details - help us to help you (click on blue link)

Moderators

There are senior members on the forums who serve as Moderators. These volunteers keep the board organized and moving.
Moderators are authorized to: (in order of increasing severity)
Move posts to the correct forums. Many times, members post in the wrong forum. These off-topic posts may impede the normal operation of the forum.
Edit posts. Moderators will edit posts that are offensive or break any of the House Rules.
Delete posts. Posts that cannot be edited to comply with the House Rules will be deleted.
Restrict members. This is one of the last punishments before a member is banned. Restrictions may include placing all new posts in a moderation queue or temporarily banning the offender.
Ban members. The most severe punishment. Three or more moderators or administrators must agree to the ban for this action to occur. Banning is reserved for very severe offenses and members who, after many warnings, fail to comply with the House Rules. Banning is permanent. Bans cannot be removed by the moderators and probably won't be removed by the administration.


The Rules

1. Warez, copyright violation, or any other illegal activity may NOT be linked or expressed in any form. Topics discussing techniques for violating these laws and messages containing locations of web sites or other servers hosting illegal content will be silently removed. Multiple offenses will result in consequences.

2. Spamming and excessive advertising will not be tolerated.

3. There will be no excessive use of profanity in any forum.

4. There will be no racial, ethnic, or gender based insults, or any other personal attacks.

5. Pictures may be attached to posts and signatures if they are not sexually explicit or offensive.

6. Remember to post in the correct forum. Take your time to look at other threads and see where your post will go. If your post is placed in the wrong forum it will be moved by a moderator.

7. If you see a post in the wrong forum or in violation of the House Rules, please contact a moderator via Private Message or the "Report this post to a moderator" link at the bottom of every post. Please do not respond directly to the member - a moderator will do what is required.

8. Any impersonation of a forum member in any mode of communication is strictly prohibited and will result in banning.

9. Multiple copies of the same post will not be tolerated. Post your question, comment, or complaint only once. There is no need to express yourself more than once. Duplicate posts will be deleted with little or no warning.

10. Posts should have descriptive subjects. Vague titles such as "Help!", "Why?", and the like may not get enough attention to the contents.

11. Do not divulge anyone's personal information in the forum, not even your own. This includes e-mail addresses, IP addresses, age, house address, and any other distinguishing information. Don´t use eMail addresses in your nick.

12. Signatures may be used as long as they are not offensive or sexually explicit.

13. Failure to show that you have read the forum rules may result in forum rules breach infraction points or warnings awarded against you which may later total up to an automatic temporary or permanent ban. Supplying system details is a prerequisite in most cases, particularly with connection or installation issues.

Violation of any of these rules will bring consequences, determined on a case-by-case basis.


Thank You! Thanks for taking the time to read these forum guidelines. We hope your visit is helpful and mutually beneficial to the entire community.


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old February 14th, 2002
Junior Member
 

Join Date: January 3rd, 2002
Location: USA,Connecticut
Posts: 12
Joetella
Lightbulb Gnutella Code

I never see any Code posted here ... just a lot of questions.. so here is a my VB Timer Event that handles connected peers and messages:

Any Questions?

Code:
Private Sub Peer_Timer(Index As Integer)
   
   Dim lbufferlength As Long
   Dim dPayloadlength As Double
   Dim bPacket() As Byte
   Dim bNothing() As Byte
   Dim bMessageHeader(0 To 22) As Byte
   Dim lBytesRead As Long
   Dim lSize As Long
   Dim lPos As Long
   
   On Error GoTo HandleError

   msPeerInfo(Index).Pinger = msPeerInfo(Index).Pinger + 1
    
   If msPeerInfo(Index).Connected = True Then
      If msPeerInfo(Index).Payload = 0 Then
         If Peer(Index).IsReadable = True And Peer(Index).RecvNext > 0 Then
            
' Read Message Header First
            lSize = msPeerInfo(Index).BytesNeeded
            ReDim bPacket(0 To lSize - 1)
            lBytesRead = Peer(Index).ReadBytes(bPacket, lSize)
            If lBytesRead > 1 Then
               msPeerInfo(Index).bytes = msPeerInfo(Index).bytes + lBytesRead
               mlBandwithIN = mlBandwithIN + lBytesRead
               If lBytesRead = 23 Then
                  If bPacket(MESSAGE_FUNCTION) = 0 Then
         
' Ping Message, go process asap
                     Call ProcessMessage(Index, bPacket, bNothing)
                     If msPeerInfo(Index).Pinger Mod 50 = 0 Then
                        Call UpdateCount(Index)
                     End If
                     msPeerInfo(Index).BytesNeeded = 23
                     Exit Sub
                  Else
                     msPeerInfo(Index).MessageHeader = bPacket
                  End If
               End If
               If lBytesRead < 23 Then
                  If msPeerInfo(Index).BytesNeeded = 23 Then
                     ReDim msPeerInfo(Index).MessageHeader(0 To 22)
                  End If
                  
                  For lPos = 0 To lBytesRead - 1
                     msPeerInfo(Index).MessageHeader(23 - msPeerInfo(Index).BytesNeeded + lPos) = bPacket(lPos)
                  Next lPos
                  
                  msPeerInfo(Index).BytesNeeded = msPeerInfo(Index).BytesNeeded - lBytesRead
                  If msPeerInfo(Index).BytesNeeded > 0 Then
                     If msPeerInfo(Index).Pinger Mod 50 = 0 Then
                        Call UpdateCount(Index)
                     End If
                     Exit Sub
                  Else
                     If msPeerInfo(Index).MessageHeader(MESSAGE_FUNCTION) = 0 Then
         
' Ping Message, go process asap
                        Call ProcessMessage(Index, msPeerInfo(Index).MessageHeader, bNothing)
                        If msPeerInfo(Index).Pinger Mod 50 = 0 Then
                           Call UpdateCount(Index)
                        End If
                        msPeerInfo(Index).BytesNeeded = 23
                        Exit Sub
                     End If
                  End If
               End If
            End If
                     
            dPayloadlength = ByteToSingle(msPeerInfo(Index).MessageHeader, PAYLOAD_START, 4)
            If dPayloadlength >= 65534 Then
               Call LogError("OverSize Error " & ByteToString(msPeerInfo(Index).MessageHeader, 0, UBound(msPeerInfo(Index).MessageHeader)) & " " & Peer(Index).Tag)
               Peer(Index).Flush
               msPeerInfo(Index).BytesNeeded = 23
               msPeerInfo(Index).Payload = 0
               Exit Sub
            End If
            msPeerInfo(Index).Payload = dPayloadlength
            msPeerInfo(Index).BytesNeeded = dPayloadlength
         End If
      End If
         
' read Payload of Message
      If msPeerInfo(Index).Payload > 0 Then
         If Peer(Index).IsReadable = True And Peer(Index).RecvNext > 0 Then
            lSize = msPeerInfo(Index).BytesNeeded
            ReDim bPacket(0 To lSize - 1)
            lBytesRead = Peer(Index).ReadBytes(bPacket, lSize)
            If lBytesRead > 0 Then
               msPeerInfo(Index).bytes = msPeerInfo(Index).bytes + lBytesRead
               mlBandwithIN = mlBandwithIN + lBytesRead
               If lBytesRead = msPeerInfo(Index).Payload Then
                  msPeerInfo(Index).MessagePayload = bPacket
                  Call ProcessMessage(Index, msPeerInfo(Index).MessageHeader, msPeerInfo(Index).MessagePayload)
                  msPeerInfo(Index).BytesNeeded = 23
                  msPeerInfo(Index).Payload = 0
               Else
                  If msPeerInfo(Index).Payload = msPeerInfo(Index).BytesNeeded Then
                     ReDim msPeerInfo(Index).MessagePayload(0 To msPeerInfo(Index).Payload - 1)
                  End If
                  
                  For lPos = 0 To lBytesRead - 1
                     msPeerInfo(Index).MessagePayload(msPeerInfo(Index).Payload - msPeerInfo(Index).BytesNeeded + lPos) = bPacket(lPos)
                  Next lPos
                  msPeerInfo(Index).BytesNeeded = msPeerInfo(Index).BytesNeeded - lBytesRead
                    
                  If msPeerInfo(Index).BytesNeeded = 0 Then
                     Call ProcessMessage(Index, msPeerInfo(Index).MessageHeader, msPeerInfo(Index).MessagePayload)
                     msPeerInfo(Index).BytesNeeded = 23
                     msPeerInfo(Index).Payload = 0
                  End If
               End If
            End If
         End If
      End If
   Else
      
' if we did not handshake connection string yet, we only need 13 bytes to get connect string
      lbufferlength = Peer(Index).RecvNext
      If lbufferlength >= 13 And msPeerInfo(Index).ConnectType = 2 Then
         If Peer(Index).IsReadable = True Then
            lSize = lbufferlength
            ReDim bPacket(0 To lSize - 1)
            lBytesRead = Peer(Index).ReadBytes(bPacket, lSize)
            mlBandwithIN = mlBandwithIN + lBytesRead
            If ByteCompare(mbGnutellaok, bPacket, 13) = True Then
               msPeerInfo(Index).Connected = True
               msPeerInfo(Index).In = 0
               Call UpdateStatus(Index, "Out")
               miOkHosts = miOkHosts + 1
               msPeerInfo(Index).Idle = 0
               msPeerInfo(Index).BytesNeeded = 23
               msPeerInfo(Index).Payload = 0
               Call Ping(Index, miTTL)
            Else
       
' if our 13 bytes did not match, must be protocol .6 i hope !
               msPeerInfo(Index).Protocol = msPeerInfo(Index).Protocol & ByteToString(bPacket, 0)
               If Right$(msPeerInfo(Index).Protocol, 4) = (vbCrLf & vbCrLf) Then
                  msPeerInfo(Index).Connected = True
                  msPeerInfo(Index).In = 0
                  Call UpdateStatus(Index, "Out")
                  Call CheckUserAgent(Index, msPeerInfo(Index).Protocol)
                  miOkHosts = miOkHosts + 1
                  msPeerInfo(Index).Idle = 0
                  msPeerInfo(Index).BytesNeeded = 23
                  msPeerInfo(Index).Payload = 0
                  
                  Peer(Index).WriteBytes mbNewOk
                  Peer(Index).WriteBytes mbUserAgent
                  Peer(Index).WriteBytes mbCRLF
                  
                  Call Ping(Index, miTTL)
               End If
            End If
         End If
      Else
         If lbufferlength >= 17 And msPeerInfo(Index).ConnectType = 1 Then
            If Peer(Index).IsReadable = True And Peer(Index).IsWritable = True Then
               Peer(Index).ReadBytes bMessageHeader, 17
               mlBandwithIN = mlBandwithIN + 17
               If ByteCompare(bMessageHeader, mbNewConnect) = True Then
                  Call UpdateStatus(Index, "Protocol")
                  msPeerInfo(Index).ConnectType = 3
                  Exit Sub
               Else
                  Call PullThePlug(Index)
               End If
            End If
         End If
         
         If lbufferlength >= 1 And msPeerInfo(Index).ConnectType = 3 Then
            If Peer(Index).IsReadable = True Then
               lSize = lbufferlength
               ReDim bPacket(0 To lSize - 1)
               lBytesRead = Peer(Index).ReadBytes(bPacket, lSize)
               msPeerInfo(Index).Protocol = msPeerInfo(Index).Protocol & ByteToString(bPacket, 0, lBytesRead)
               If Right$(msPeerInfo(Index).Protocol, 2) = (vbLf & vbLf) Then
                  
' old style Connect .4
                  msPeerInfo(Index).Protocol = "GNUTELLA CONNECT/" & msPeerInfo(Index).Protocol
                  msPeerInfo(Index).Connected = True
                  msPeerInfo(Index).In = 0
                  msPeerInfo(Index).Pinger = 1
                  msPeerInfo(Index).BytesNeeded = 23
                  msPeerInfo(Index).Payload = 0
                  Call UpdateStatus(Index, "In")
                  Peer(Index).WriteBytes mbGnutellaok
                  miOkHosts = miOkHosts + 1
                  msPeerInfo(Index).Idle = 0
                  Call Ping(Index, miTTL)
                  Exit Sub
               End If
               If Right$(msPeerInfo(Index).Protocol, 4) = (vbCrLf & vbCrLf) Then
                  
' new style Connect .6
                  msPeerInfo(Index).Connected = True
                  msPeerInfo(Index).In = 0
                  msPeerInfo(Index).Pinger = 1
                  msPeerInfo(Index).BytesNeeded = 23
                  msPeerInfo(Index).Payload = 0
                  Call UpdateStatus(Index, "In")
                  Peer(Index).WriteBytes mbNewOk
                  Peer(Index).WriteBytes mbUserAgent
                  Peer(Index).WriteBytes mbCRLF
                  miOkHosts = miOkHosts + 1
                  msPeerInfo(Index).Idle = 0
                  Call Ping(Index, miTTL)
                  
' Add Host name to Peer Listview
                  Call CheckUserAgent(Index, msPeerInfo(Index).Protocol)
               End If
            End If
         End If
      End If
   End If
     
HandleError:

   Err.Clear
   On Error Resume Next
   If msPeerInfo(Index).Pinger Mod 50 = 0 Then
      Call UpdateCount(Index)
   End If
 
End Sub

Last edited by Joetella : February 14th, 2002 at 07:04 PM.
Reply With Quote
  #2 (permalink)  
Old February 16th, 2002
Unregistered
 

Posts: n/a
Default

my god, why not just write it in C ? it looks like "almost C" or "wanta-be C"
it would run faster too.
Reply With Quote
  #3 (permalink)  
Old February 19th, 2002
Junior Member
 

Join Date: January 3rd, 2002
Location: USA,Connecticut
Posts: 12
Joetella
Default

is trying to write structured code a bad thing?
Reply With Quote
  #4 (permalink)  
Old February 19th, 2002
Phex Developer
 

Join Date: May 8th, 2001
Location: Stuttgart, Germany
Posts: 867
GregorK
Default

This dosent look structured at all...
__________________
Reply With Quote
  #5 (permalink)  
Old February 20th, 2002
Morgwen's Avatar
lazy dragon - retired mod
 

Join Date: October 14th, 2001
Location: Germany
Posts: 2,929
Morgwen is on a distinguished road
Default

Quote:
Originally posted by GregorK
This dosent look structured at all...
Do you have some tips for him?

Morgwen
Reply With Quote
  #6 (permalink)  
Old February 20th, 2002
Phex Developer
 

Join Date: May 8th, 2001
Location: Stuttgart, Germany
Posts: 867
GregorK
Default

The code is some times nested up to 8 levels or maybe more. In almost every style guide you will read that you should not use more then 3 or maybe 4 levels. Instead try to use sub method calls. This makes things much easier to read and understand.

Also you can sometimes limit nesting with reversing the condition.

Instead of saying:

If example = True Then
If example2 = True Then
...... VERY LONG CODE LIST.....
end if
end if

you can say:

If example = False Then
return
end if
If example2 = False Then
return
end if
...... VERY LONG CODE LIST.....


Don't know the exact syntax but I hope you understand my intention.
Reply With Quote
  #7 (permalink)  
Old February 20th, 2002
Junior Member
 

Join Date: January 3rd, 2002
Location: USA,Connecticut
Posts: 12
Joetella
Default

Quote:
Originally posted by GregorK
The code is some times nested up to 8 levels or maybe more. In almost every style guide you will read that you should not use more then 3 or maybe 4 levels. Instead try to use sub method calls. This makes things much easier to read and understand.

Also you can sometimes limit nesting with reversing the condition.

Instead of saying:

If example = True Then
If example2 = True Then
...... VERY LONG CODE LIST.....
end if
end if

you can say:

If example = False Then
return
end if
If example2 = False Then
return
end if
...... VERY LONG CODE LIST.....


Don't know the exact syntax but I hope you understand my intention.
Just a matter of style I guess .. I actually dont like multiple returns/exit points (however i do have some!) ... and normally would write code like the first example to avoid it !

However I do have to many nested If/Thens .. or flying ducks

Joe

Last edited by Joetella : February 20th, 2002 at 05:24 AM.
Reply With Quote
Reply



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Simulate Gnutella v0.6: can i use existing code/libraries? iasty General Gnutella Development Discussion 6 April 17th, 2008 03:05 PM
Gnutella crawler source code? Navigator_121 General Gnutella Development Discussion 2 December 14th, 2005 10:53 AM
Gnutella Source Code bmarini General Gnutella Development Discussion 1 February 18th, 2003 10:34 PM
Where I can find source code to made my own Gnutella Client or Web search site ? avsolo Site Feedback 1 February 18th, 2001 03:28 AM
Where I acn fine source code to made my own Gnutella Client or web search site ? avsolo General Gnutella / Gnutella Network Discussion 1 February 18th, 2001 03:28 AM


All times are GMT -7. The time now is 02:07 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0

Copyright © 2007 Gnutelliums LLC.
All Rights Reserved.