Bitcoin Forum
May 04, 2024, 12:10:39 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Is there a way to check if my Message is valid (Version handshake,...)  (Read 621 times)
Coding Enthusiast (OP)
Legendary
*
Offline Offline

Activity: 1039
Merit: 2783


Bitcoin and C♯ Enthusiast


View Profile WWW
December 11, 2016, 09:23:31 AM
Last edit: December 14, 2016, 06:14:21 PM by Coding Enthusiast
Merited by ABCbits (6)
 #1

Since I am learning I wanted to know if there there is a way to check if the Message I have generated is valid before sending it out?

I am talking about Messages that you send to a node in order to establish communication, starting with version.

Example based on Docs
Quote
My header:
f9beb4d9
76657273696f6e0000000000
cc0000006a000000
3fd3a680


My message:
7e110100
0000000000000000
fa084d5800000000
0000000000000000
00000000000000000000ffff52a1377f
208d
0000000000000000
00000000000000000000ffff7f000001
208d
fa084d5800000000
2814 2f437573746f6d436c69656e743a302e392e302f
00000000
00


A couple of questions regarding this:
1) Why should I even provide "addr_recv services" field? And does it matter if I provide 0 or 1?
2) Will receiving node reject "addr_recv IP address" field if it is 127.0.0.1 instead of its own IP or a false IP?
3) "addr_trans services" Why am I telling this again if it is identical to "services" above?
4) I don't get usage of "nonce" when I have already provided "timestamp" which will change every time it is generated and it will be bigger. And can I use the same thing again here?
5) What is the criteria to get banned by a node? For instance will I be banned if I send a wrong message on first attempt? Also will I receive any reply if my message contains errors or will it be ignored?

Projects List+Suggestion box
Donate: 1Q9s or bc1q
|
|
|
FinderOuter(0.19.1)Ann-git
Denovo(0.7.0)Ann-git
Bitcoin.Net(0.26.0)Ann-git
|
|
|
BitcoinTransactionTool(0.11.0)Ann-git
WatchOnlyBitcoinWallet(3.2.1)Ann-git
SharpPusher(0.12.0)Ann-git
"I'm sure that in 20 years there will either be very large transaction volume or no volume." -- Satoshi
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714824639
Hero Member
*
Offline Offline

Posts: 1714824639

View Profile Personal Message (Offline)

Ignore
1714824639
Reply with quote  #2

1714824639
Report to moderator
1714824639
Hero Member
*
Offline Offline

Posts: 1714824639

View Profile Personal Message (Offline)

Ignore
1714824639
Reply with quote  #2

1714824639
Report to moderator
1714824639
Hero Member
*
Offline Offline

Posts: 1714824639

View Profile Personal Message (Offline)

Ignore
1714824639
Reply with quote  #2

1714824639
Report to moderator
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3388
Merit: 6581


Just writing some code


View Profile WWW
December 11, 2016, 03:59:21 PM
Merited by ABCbits (4), EFS (2)
 #2

1) Why should I even provide "addr_recv services" field? And does it matter if I provide 0 or 1?
I don't think it matters.

2) Will receiving node reject "addr_recv IP address" field if it is 127.0.0.1 instead of its own IP or a false IP?
It shouldn't, but you should still attempt to provide the correct IP.

3) "addr_trans services" Why am I telling this again if it is identical to "services" above?
Because....

4) I don't get usage of "nonce" when I have already provided "timestamp" which will change every time it is generated and it will be bigger. And can I use the same thing again here?
Code:
A random nonce which can help a node detect a connection to itself. If the nonce is 0, the nonce field is ignored. If the nonce is anything else, a node should terminate the connection on receipt of a version message with a nonce it previously sent.
Just use 0.

5) What is the criteria to get banned by a node? For instance will I be banned if I send a wrong message on first attempt? Also will I receive any reply if my message contains errors or will it be ignored?
You won't get banned on the first time that you try. Just don't send bad messages too many times too quickly and you should be fine.

You should test this against your own local node and you can set it to never ban the node that you are testing.


You should use wireshark to see the messages actually sent by nodes so that you can check your own message and see how the messages are usually done.

valley365
Hero Member
*****
Offline Offline

Activity: 868
Merit: 1003


View Profile
December 12, 2016, 09:30:00 AM
 #3

if you create message on your own (i.e. not using bitcoin framework), then you need to make sure the message starts with particular sequence which is defined by the pchMessageStart array. For bitcoin it is defined as:
        pchMessageStart[0] = 0xf9;
        pchMessageStart[1] = 0xbe;
        pchMessageStart[2] = 0xb4;
        pchMessageStart[3] = 0xd9;

other coins such as litecoin have different definition, that's how the coin recognize its own message.
Coding Enthusiast (OP)
Legendary
*
Offline Offline

Activity: 1039
Merit: 2783


Bitcoin and C♯ Enthusiast


View Profile WWW
December 12, 2016, 02:25:39 PM
 #4

@valley365
Sorry I thought my question was clear that I am creating the message on my own based on the documentation not with any software or library out there. And that example in OP is the message I have generated with my own code.


I will update this topic, right now I apparently have some troubles with my understanding of TCP Grin and how to use a freaking Socket!

Projects List+Suggestion box
Donate: 1Q9s or bc1q
|
|
|
FinderOuter(0.19.1)Ann-git
Denovo(0.7.0)Ann-git
Bitcoin.Net(0.26.0)Ann-git
|
|
|
BitcoinTransactionTool(0.11.0)Ann-git
WatchOnlyBitcoinWallet(3.2.1)Ann-git
SharpPusher(0.12.0)Ann-git
Foxpup
Legendary
*
Offline Offline

Activity: 4354
Merit: 3042


Vile Vixen and Miss Bitcointalk 2021-2023


View Profile
December 12, 2016, 03:11:34 PM
 #5

@valley365
Sorry I thought my question was clear that I am creating the message on my own based on the documentation not with any software or library out there. And that example in OP is the message I have generated with my own code.
Your question was perfectly clear; he's just posting nonsense for his sig campaign. I already reported it.

Will pretend to do unspeakable things (while actually eating a taco) for bitcoins: 1K6d1EviQKX3SVKjPYmJGyWBb1avbmCFM4
I am not on the scammers' paradise known as Telegram! Do not believe anyone claiming to be me off-forum without a signed message from the above address! Accept no excuses and make no exceptions!
Coding Enthusiast (OP)
Legendary
*
Offline Offline

Activity: 1039
Merit: 2783


Bitcoin and C♯ Enthusiast


View Profile WWW
December 14, 2016, 06:35:35 PM
 #6

As an update I want to say the Wireshark helped a lot. My mistake in my message was the length fields which I forgot to cut in half (hex length/2) and also it was interesting to find out that the receiving node returns a reply even to messages with error like mine with a reject message saying error parsing message
https://bitcoin.org/en/developer-reference#reject

Now I've got to figure out how to stack these send and received on top of each other using threading.

Something weird: the node that I sent the wrong message to replied with the following messages respectively!
  • reject
  • ping
  • getheaders
  • addr
  • inv
the weird part is that it skips version and verack!
Until both peers have exchanged version messages, no other messages will be accepted.
I guess that only goes for "accepting" not "sending"?!

Projects List+Suggestion box
Donate: 1Q9s or bc1q
|
|
|
FinderOuter(0.19.1)Ann-git
Denovo(0.7.0)Ann-git
Bitcoin.Net(0.26.0)Ann-git
|
|
|
BitcoinTransactionTool(0.11.0)Ann-git
WatchOnlyBitcoinWallet(3.2.1)Ann-git
SharpPusher(0.12.0)Ann-git
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!