From e2c42668ae1297fd4bdda960a7daf73c50db4db7 Mon Sep 17 00:00:00 2001 From: Javier Vargas Date: Fri, 26 Jun 2020 17:05:47 +0200 Subject: [PATCH 01/21] Create 15_3_Receiving_Bitcoind_Notifications_with_C.md --- ...Receiving_Bitcoind_Notifications_with_C.md | 196 ++++++++++++++++++ 1 file changed, 196 insertions(+) create mode 100644 15_3_Receiving_Bitcoind_Notifications_with_C.md diff --git a/15_3_Receiving_Bitcoind_Notifications_with_C.md b/15_3_Receiving_Bitcoind_Notifications_with_C.md new file mode 100644 index 0000000..4db5ec8 --- /dev/null +++ b/15_3_Receiving_Bitcoind_Notifications_with_C.md @@ -0,0 +1,196 @@ +# 15.3 Receiving Bitcoind Notifications with C + +> **NOTE:** This is a draft in progress, so that I can get some feedback from early reviewers. It is not yet ready for learning. + +[ยง15.3](15_3_Receiving_Bitcoind_Notifications_with_C.md) In this chapter we will show how to create a simple listener for bitcoin blockchain to receive notifications using ZMQ-based (http://zeromq.org/) notification interface, which is a highly scalable networking library written in C that acts like a concurrency framework. Bitcoin allows connection points where clients can subscribe to get notified about blockchain events like raw transactions or raw blocks. + +## Install ZMQ + +To create a blockchain listener in C you need to install ZMQ following this steps. + + 1. Install ZMQ + 2. Create C program. + 3. Compile C program. + 4. Configure bitcoind to allow ZMQ notifications + 5. Execute listener. + +### 1. Install ZMQ + +``` +sudo apt-get install libzmq3-dev +``` +Output + +``` +Reading package lists... Done +Building dependency tree +Reading state information... Done +The following NEW packages will be installed: + libzmq3-dev +0 upgraded, 1 newly installed, 0 to remove and 18 not upgraded. +Need to get 400 kB of archives. +After this operation, 2.227 kB of additional disk space will be used. +Get:1 http://es.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 libzmq3-dev amd64 4.2.5-1ubuntu0.2 [400 kB] +Fetched 400 kB in 0s (1.114 kB/s) +Selecting previously unselected package libzmq3-dev:amd64. +(Reading database ... 313982 files and directories currently installed.) +Preparing to unpack .../libzmq3-dev_4.2.5-1ubuntu0.2_amd64.deb ... +Unpacking libzmq3-dev:amd64 (4.2.5-1ubuntu0.2) ... +Setting up libzmq3-dev:amd64 (4.2.5-1ubuntu0.2) ... +Processing triggers for man-db (2.8.3-2ubuntu0.1) ... +``` +Then + +``` +sudo apt-get install libczmq-dev +``` +Output: + +``` +Reading package lists... Done +Building dependency tree +Reading state information... Done +The following additional packages will be installed: + libczmq4 +The following NEW packages will be installed: + libczmq-dev libczmq4 +0 upgraded, 2 newly installed, 0 to remove and 18 not upgraded. +Need to get 496 kB of archives. +After this operation, 2.148 kB of additional disk space will be used. +Do you want to continue? [Y/n] y +Get:1 http://es.archive.ubuntu.com/ubuntu bionic/universe amd64 libczmq4 amd64 4.1.0-2 [145 kB] +Get:2 http://es.archive.ubuntu.com/ubuntu bionic/universe amd64 libczmq-dev amd64 4.1.0-2 [351 kB] +Fetched 496 kB in 0s (1.287 kB/s) +Selecting previously unselected package libczmq4:amd64. +(Reading database ... 314055 files and directories currently installed.) +Preparing to unpack .../libczmq4_4.1.0-2_amd64.deb ... +Unpacking libczmq4:amd64 (4.1.0-2) ... +Selecting previously unselected package libczmq-dev:amd64. +Preparing to unpack .../libczmq-dev_4.1.0-2_amd64.deb ... +Unpacking libczmq-dev:amd64 (4.1.0-2) ... +Setting up libczmq4:amd64 (4.1.0-2) ... +Setting up libczmq-dev:amd64 (4.1.0-2) ... +Processing triggers for man-db (2.8.3-2ubuntu0.1) ... +Processing triggers for libc-bin (2.27-3ubuntu1) ... +``` + +### 2. Create C Program + +Now we've installed ZMQ and we can compile our C program using it's notifications. +The program use czmq.h library and receives two parameters as follows, first param is the point exposed by bitcoind and second the topic about we'll listen. + +``` c +#include +int main(int argc, char ** argv) { + + char *zmqserver; + char *topic; + + if (argc < 3) { + printf("\nUSAGE:\nchainlistener \n\n"); + return 0; + } else { + zmqserver = argv[1]; + topic = argv[2]; + } + + zsock_t *socket = zsock_new_sub(zmqserver, topic); + assert(socket); + + while(1) { + zmsg_t *msg; + int rc = zsock_recv(socket, "m", &msg); + assert(rc == 0); + + char *header = zmsg_popstr(msg); + zframe_t *zdata = zmsg_pop(msg); + unsigned int *no = (unsigned int*)zmsg_popstr(msg); + + char *data = zframe_strhex(zdata); + int len = zframe_size(zdata); + printf("Size: %d\n", len); + printf("Data: %s", data); + printf("\nNo: %d\n", *no); + + free(header); + free(data); + free(no); + free(zdata); + zmsg_destroy(&msg); + sleep(1); + } + zsock_destroy(&socket); + return 0; +} +``` + +### 3. Compile C program + +To compile this C program you have to do it with clang or gcc compiler and test zmq and czmq libraries. + +``` +gcc -o chainlistener chainlistener.c -I/usr/local/include -L/usr/local/lib -lzmq -lczmq +``` + +### 4. Configure ZMQ on bitcoind + +Add this lines to bitcoin.conf file and restart daemon. + +``` +zmqpubrawblock=tcp://127.0.0.1:28332 +zmqpubrawtx=tcp://127.0.0.1:28333 +``` +Then test it's working using this command + +``` +$ bitcoin-cli --testnet getzmqnotifications +``` +Output: +``` +[ + { + "type": "pubrawblock", + "address": "tcp://127.0.0.1:28332", + "hwm": 1000 + }, + { + "type": "pubrawtx", + "address": "tcp://127.0.0.1:28333", + "hwm": 1000 + } +] +``` +### 5. Execute listener: + +``` +$ ./chainlistener tcp://127.0.0.1:28333 rawtx +Size: 250 +Data: 02000000000101F5BD2032E5A9E6650D4E411AD272E391F26AFC3C9102B7C0C7444F8F74AE86010000000017160014AE9D51ADEEE8F46ED2017F41CD631D210F2ED9C5FEFFFFFF0203A732000000000017A9147231060F1CDF34B522E9DB650F44EDC6C0714E4C8710270000000000001976A914262437B129CF8592AB2EDC59C07D19C57729F72888AC02483045022100AE316D5F21657E3525271DE39EB285D8A0E89A20AB6413824E88CE47DCD0EFE702202F61E10C2A8F4A7125D5EB63AEF883D8E3584A0ECED0D349283AABB6CA5E066D0121035A77FE575A9005E3D3FF0682E189E753E82FA8BFF0A20F8C45F06DC6EBE3421079111B00 +No: 67 +Size: 249 +Data: 0200000000010165C986992F7DAD22BBCE3FCF0BF546EDBC3C599618B04CFA22D9E64EF0CE4C030000000017160014B58E0A5CD68B249F1C407E9AAE9CD0332AAA3067FEFFFFFF02637932000000000017A914CCC47261489036CB6B9AA610857793FF5752E5378710270000000000001976A914262437B129CF8592AB2EDC59C07D19C57729F72888AC0247304402206CCC3F3B4BE01D4E532A01C2DC6BC3B53E4FFB6B494C8B87DD603EFC648A159902201653841E8B16A814DC375129189BB7CF01CFF7D269E91178645B6A97F5C7F4F10121030E20F3D2F172281B8DC747F007DF24B352248AC09E48CA64016942A8F01D317079111B00 +No: 68 +Size: 250 +Data: 02000000000101E889CFC1FFE127BA49F6C1011388606A194109AE1EDAAB9BEE215E123C14A7920000000017160014577B0B3C2BF91B33B5BD70AE9E8BD8144F4B87E7FEFFFFFF02C34B32000000000017A914A9F1440402B46235822639C4FD2F78A31E8D269E8710270000000000001976A914262437B129CF8592AB2EDC59C07D19C57729F72888AC02483045022100B46318F53E1DCE63E7109DB4FA54AF40AADFC2FEB0E08263756BC3B7A6A744CB02200851982AF87DBABDC3DFC3362016ECE96AECFF50E24D9DCF264AE8966A5646FE0121039C90FCB46AEA1530E5667F8FF15CB36169D2AD81247472F236E3A3022F39917079111B00 +No: 69 +Size: 250 +Data: 0200000000010137527957C9AD6CFF0C9A74597E6EFCD7E1EBD53E942AB2FA34A831046CA11488000000001716001429BFF05B3CD79E9CCEFDB5AE82139F72EB3E9DB0FEFFFFFF0210270000000000001976A914262437B129CF8592AB2EDC59C07D19C57729F72888AC231E32000000000017A9146C8D5FE29BFDDABCED0D6F4D8E82DCBFD9D34A8B8702483045022100F259846BAE29EB2C7A4AD711A3BC6109DE69AE91E35B14CA2742157894DD9760022021464E09C00ABA486AEAA0C49FEE12D2850DC03F57F04A1A9E2CC4D0F4F1459C012102899F24A9D60132F4DD1A5BA6DCD1E4E4B6C728927BA482C2C4E511679F60CA5779111B00 +No: 70 +....... +``` + + +### For More Information + +In this repository you can browse find more details about ZMQ notifications and others kind of messages. (https://github.com/Actinium-project/ChainTools/blob/master/docs/chainlistener.md) + +### Summary Receiving Bitcoind Notifications with C.md + +By using ZMQ framework, you can easily receive notifications by subscribing to a connection point exposed by bitcoind changing configuration file. + + + + + + + From 785eb9b6b0429b26068e4dddcde915f9a4afaa63 Mon Sep 17 00:00:00 2001 From: Javier Vargas Date: Fri, 26 Jun 2020 19:05:03 +0200 Subject: [PATCH 02/21] Update 12_0_Using_Tor.md --- 12_0_Using_Tor.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/12_0_Using_Tor.md b/12_0_Using_Tor.md index 864a2e4..1528fb4 100644 --- a/12_0_Using_Tor.md +++ b/12_0_Using_Tor.md @@ -4,6 +4,6 @@ _This is currently a placeholder; Writing it in Task #15 on the current [TODO li This section will talk about using the Tor services that are now available courtesy of Bitcoin Standup._) - * 12.1: Verifying Your Tor Setup + * [12.1: Verifying Your Tor Setup](https://github.com/BlockchainCommons/Learning-Bitcoin-from-the-Command-Line/12_1_Verifying_Your_Tor_Setup) * 12.2: Changing Your Bitcoin Hidden Services * 12.3: Adding SSH Hiddne Services From aa551bed03eabce23887060d8d26ebd430e364b6 Mon Sep 17 00:00:00 2001 From: Javier Vargas Date: Fri, 26 Jun 2020 22:21:49 +0200 Subject: [PATCH 03/21] Update 12_0_Using_Tor.md --- 12_0_Using_Tor.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/12_0_Using_Tor.md b/12_0_Using_Tor.md index 1528fb4..8d2c560 100644 --- a/12_0_Using_Tor.md +++ b/12_0_Using_Tor.md @@ -4,6 +4,6 @@ _This is currently a placeholder; Writing it in Task #15 on the current [TODO li This section will talk about using the Tor services that are now available courtesy of Bitcoin Standup._) - * [12.1: Verifying Your Tor Setup](https://github.com/BlockchainCommons/Learning-Bitcoin-from-the-Command-Line/12_1_Verifying_Your_Tor_Setup) + * [12.1: Verifying Your Tor Setup](12_1_Verifying_Your_Tor_Setup) * 12.2: Changing Your Bitcoin Hidden Services * 12.3: Adding SSH Hiddne Services From a3df9f260b9b31d546f6a3e80c5cec40cae9b274 Mon Sep 17 00:00:00 2001 From: Javier Vargas Date: Fri, 26 Jun 2020 22:23:00 +0200 Subject: [PATCH 04/21] Create 12_1_Verifying_Your_Tor_Setup.md --- 12_1_Verifying_Your_Tor_Setup.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 12_1_Verifying_Your_Tor_Setup.md diff --git a/12_1_Verifying_Your_Tor_Setup.md b/12_1_Verifying_Your_Tor_Setup.md new file mode 100644 index 0000000..b253e13 --- /dev/null +++ b/12_1_Verifying_Your_Tor_Setup.md @@ -0,0 +1,18 @@ +# Chapter 12: Verifying Your Tor Setup + +In this chapter we will verify tor installation and setup. + +``` +~$ sudo -u debian-tor tor --verify-config +``` + +If tor is installed correctly you should see an output like this: + +``` +Jun 26 21:52:09.230 [notice] Tor 0.4.3.5 running on Linux with Libevent 2.0.21-stable, OpenSSL 1.0.2n, Zlib 1.2.11, Liblzma 5.2.2, and Libzstd N/A. +Jun 26 21:52:09.230 [notice] Tor can't help you if you use it wrong! Learn how to be safe at https://www.torproject.org/download/download#warning +Jun 26 21:52:09.230 [notice] Read configuration file "/etc/tor/torrc". +Configuration was valid + +~$ +``` From d938af4e91f187c2782c0ec84fef06e6d3a7057d Mon Sep 17 00:00:00 2001 From: Javier Vargas Date: Fri, 26 Jun 2020 22:24:06 +0200 Subject: [PATCH 05/21] Update 12_0_Using_Tor.md --- 12_0_Using_Tor.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/12_0_Using_Tor.md b/12_0_Using_Tor.md index 8d2c560..eb09b60 100644 --- a/12_0_Using_Tor.md +++ b/12_0_Using_Tor.md @@ -4,6 +4,6 @@ _This is currently a placeholder; Writing it in Task #15 on the current [TODO li This section will talk about using the Tor services that are now available courtesy of Bitcoin Standup._) - * [12.1: Verifying Your Tor Setup](12_1_Verifying_Your_Tor_Setup) + * [12.1: Verifying Your Tor Setup](https://github.com/javiervargas/Learning-Bitcoin-from-the-Command-Line/blob/master/12_1_Verifying_Your_Tor_Setup.md) * 12.2: Changing Your Bitcoin Hidden Services * 12.3: Adding SSH Hiddne Services From e5a3882af7d23bce7cb12b002f7dc7fb4ed8f46c Mon Sep 17 00:00:00 2001 From: Javier Vargas Date: Tue, 30 Jun 2020 22:33:36 +0200 Subject: [PATCH 06/21] Create 12_2_Changing_Your_Bitcoin_Hidden_Services.md --- 12_2_Changing_Your_Bitcoin_Hidden_Services.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 12_2_Changing_Your_Bitcoin_Hidden_Services.md diff --git a/12_2_Changing_Your_Bitcoin_Hidden_Services.md b/12_2_Changing_Your_Bitcoin_Hidden_Services.md new file mode 100644 index 0000000..a882878 --- /dev/null +++ b/12_2_Changing_Your_Bitcoin_Hidden_Services.md @@ -0,0 +1,18 @@ +# Chapter 12.2: Changing Your Bitcoin Hidden Services + +In this chapter we will show you how to create or change your local Bitcoin Hidden Service. To archieve this we need to add current user to tor or debian-tor group to guarantee that Bitcoin daemon can sets up an automatic hidden service on the first startup if it's correclty configured. Bitcoind will create a file called onion_private_key in the data directory. Further check if file control.authcookie exists like this: + +``` +~$ ll /run/tor/control.authcookie +-rw-r----- 1 debian-tor debian-tor 32 jun 26 09:44 /run/tor/control.authcookie +``` + +Add your user to debian-tor group like this: + +``` +~$ sudo usermod -a -G debian-tor [CHANGE_MY_USER] +``` + + + ll /run/tor/control.authcookie +-rw-r----- 1 debian-tor debian-tor 32 jun 26 09:44 /run/tor/control.authcookie From 0f7543aaa367db94119f0baf3af8370934ae434e Mon Sep 17 00:00:00 2001 From: Javier Vargas Date: Tue, 30 Jun 2020 23:07:03 +0200 Subject: [PATCH 07/21] Update 12_1_Verifying_Your_Tor_Setup.md --- 12_1_Verifying_Your_Tor_Setup.md | 70 ++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/12_1_Verifying_Your_Tor_Setup.md b/12_1_Verifying_Your_Tor_Setup.md index b253e13..ed4de3a 100644 --- a/12_1_Verifying_Your_Tor_Setup.md +++ b/12_1_Verifying_Your_Tor_Setup.md @@ -16,3 +16,73 @@ Configuration was valid ~$ ``` +## Verify bitcoind Tor setup + +You should see something like this in your debug log file to verify your ID onion address. + +``` +$ grep -e "tor: " debug.log +``` +Output + +``` +2020-06-25T18:16:44Z tor: Thread interrupt +2020-06-25T19:11:12Z tor: Got service ID [YOUR_ONION_ID], advertising service your_onion_id.onion:8333 +``` +Using bitcoin-cli you should use: + +``` +$ bitcoin-cli getnetworkinfo +``` +Output + +``` +{ + "version": 200000, + "subversion": "/Satoshi:0.20.0/", + "protocolversion": 70015, + "localservices": "0000000000000409", + "localservicesnames": [ + "NETWORK", + "WITNESS", + "NETWORK_LIMITED" + ], + "localrelay": true, + "timeoffset": 0, + "networkactive": true, + "connections": 5, + "networks": [ + { + "name": "ipv4", + "limited": false, + "reachable": true, + "proxy": "", + "proxy_randomize_credentials": false + }, + { + "name": "ipv6", + "limited": false, + "reachable": true, + "proxy": "", + "proxy_randomize_credentials": false + }, + { + "name": "onion", + "limited": false, + "reachable": true, + "proxy": "127.0.0.1:9050", + "proxy_randomize_credentials": true + } + ], + "relayfee": 0.00001000, + "incrementalfee": 0.00001000, + "localaddresses": [ + { + "address": "your_onion_id.onion", + "port": 8333, + "score": 4 + } + ], + "warnings": "" +} +``` From 710a9f88f7a00c2eb50bba47a2bfbe0778245799 Mon Sep 17 00:00:00 2001 From: Javier Vargas Date: Tue, 30 Jun 2020 23:10:22 +0200 Subject: [PATCH 08/21] Update 12_0_Using_Tor.md --- 12_0_Using_Tor.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/12_0_Using_Tor.md b/12_0_Using_Tor.md index eb09b60..ac8086b 100644 --- a/12_0_Using_Tor.md +++ b/12_0_Using_Tor.md @@ -4,6 +4,6 @@ _This is currently a placeholder; Writing it in Task #15 on the current [TODO li This section will talk about using the Tor services that are now available courtesy of Bitcoin Standup._) - * [12.1: Verifying Your Tor Setup](https://github.com/javiervargas/Learning-Bitcoin-from-the-Command-Line/blob/master/12_1_Verifying_Your_Tor_Setup.md) - * 12.2: Changing Your Bitcoin Hidden Services + * [12.1: Verifying Your Tor Setup](12_1_Verifying_Your_Tor_Setup.md) + * [12.2: Changing Your Bitcoin Hidden Services](12_2_Changing_Your_Bitcoin_Hidden_Services.md) * 12.3: Adding SSH Hiddne Services From d9d73b6574ff167ce9fee39d07069714fb9bd1b8 Mon Sep 17 00:00:00 2001 From: Javier Vargas Date: Tue, 30 Jun 2020 23:26:24 +0200 Subject: [PATCH 09/21] Update 12_1_Verifying_Your_Tor_Setup.md --- 12_1_Verifying_Your_Tor_Setup.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/12_1_Verifying_Your_Tor_Setup.md b/12_1_Verifying_Your_Tor_Setup.md index ed4de3a..64e078e 100644 --- a/12_1_Verifying_Your_Tor_Setup.md +++ b/12_1_Verifying_Your_Tor_Setup.md @@ -18,7 +18,7 @@ Configuration was valid ``` ## Verify bitcoind Tor setup -You should see something like this in your debug log file to verify your ID onion address. +You should see something like this in your debug log file to verify your ID onion address, which confirms you're using an onion hidden service that will bypass firewalls and NAT's and allows you connect to your node remotely using your ID and port. ``` $ grep -e "tor: " debug.log From 3b12f64b1f748dbb923e06b6f80cff6d0d4bac0b Mon Sep 17 00:00:00 2001 From: Javier Vargas Date: Tue, 30 Jun 2020 23:42:52 +0200 Subject: [PATCH 10/21] Update 15_3_Receiving_Bitcoind_Notifications_with_C.md --- 15_3_Receiving_Bitcoind_Notifications_with_C.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/15_3_Receiving_Bitcoind_Notifications_with_C.md b/15_3_Receiving_Bitcoind_Notifications_with_C.md index 4db5ec8..d638c90 100644 --- a/15_3_Receiving_Bitcoind_Notifications_with_C.md +++ b/15_3_Receiving_Bitcoind_Notifications_with_C.md @@ -76,7 +76,7 @@ Processing triggers for libc-bin (2.27-3ubuntu1) ... ### 2. Create C Program -Now we've installed ZMQ and we can compile our C program using it's notifications. +Now we've installed ZMQ and we can compile our C program using it's notifications. This C program it's a simple client that subscribes to a connection point served by bitcoind and ZMQ interface and reads incoming messages. The program use czmq.h library and receives two parameters as follows, first param is the point exposed by bitcoind and second the topic about we'll listen. ``` c From b3145deca7925f4336a5b953e41b6b6784f8ca26 Mon Sep 17 00:00:00 2001 From: Javier Vargas Date: Wed, 1 Jul 2020 13:59:26 +0200 Subject: [PATCH 11/21] Update 15_3_Receiving_Bitcoind_Notifications_with_C.md --- ...Receiving_Bitcoind_Notifications_with_C.md | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/15_3_Receiving_Bitcoind_Notifications_with_C.md b/15_3_Receiving_Bitcoind_Notifications_with_C.md index d638c90..7b06a41 100644 --- a/15_3_Receiving_Bitcoind_Notifications_with_C.md +++ b/15_3_Receiving_Bitcoind_Notifications_with_C.md @@ -76,8 +76,14 @@ Processing triggers for libc-bin (2.27-3ubuntu1) ... ### 2. Create C Program -Now we've installed ZMQ and we can compile our C program using it's notifications. This C program it's a simple client that subscribes to a connection point served by bitcoind and ZMQ interface and reads incoming messages. -The program use czmq.h library and receives two parameters as follows, first param is the point exposed by bitcoind and second the topic about we'll listen. +Now we've installed ZMQ and we can compile our C program using it's notifications. This C program it's a simple client that subscribes to a connection point served by bitcoind and ZMQ interface and reads incoming messages. +The program use czmq.h library and receives two parameters as follows, first param is the point exposed by bitcoind that should be tcp connection point depending second param that could be one of these: + +zmqpubrawblock +zmqpubrawtx +zmqpubhashtx +zmqpubhashblock + ``` c #include @@ -134,6 +140,24 @@ gcc -o chainlistener chainlistener.c -I/usr/local/include -L/usr/local/lib -lzmq ### 4. Configure ZMQ on bitcoind +#### ZMQ + +ZeroMQ is a high-performance asynchronous messaging library that provides a message queue. ZeroMQ supports common messaging patterns (pub/sub, request/reply, client/server and others) over a variety of transports (TCP, in-process, inter-process, multicast, WebSocket and more), making inter-process messaging as simple as inter-thread messaging. As the purpose of this chapter is to show how to receive bitcoind notifications in the C language, ZMQ will be used for it. + +Currently, the ZeroMQ facility only needs to have the ZeroMQ endpoint specified. ZeroMQ publish sockets prepend each data item with an arbitrary topic +prefix that allows subscriber clients to request only those items with a matching prefix. + +Topics. + +``` +zmqpubrawblock=tcp://127.0.0.1:28332 +zmqpubrawtx=tcp://127.0.0.1:28333 +zmqpubhashtx=tcp://127.0.0.1:28334 +zmqpubhashblock=tcp://127.0.0.1:28335 +``` + +In this example we'll use raw tx that is the topic that notifies about new transactions in raw format. + Add this lines to bitcoin.conf file and restart daemon. ``` @@ -162,6 +186,8 @@ Output: ``` ### 5. Execute listener: +When you execute chainlistener and passes these params you'll get an output like this: + ``` $ ./chainlistener tcp://127.0.0.1:28333 rawtx Size: 250 @@ -178,7 +204,9 @@ Data: 0200000000010137527957C9AD6CFF0C9A74597E6EFCD7E1EBD53E942AB2FA34A831046CA1 No: 70 ....... ``` +The first param it's bitcoind connection point where ZMQ will notifies all about transactions in raw format. It corresponds to this line in bitcoin.conf file zmqpubrawtx=tcp://127.0.0.1:28333 +The second param is the topic selected rawtx explained above. ### For More Information From 0ee6893d477259b979b3a5ca8c51ee0f7d34fd20 Mon Sep 17 00:00:00 2001 From: Javier Vargas Date: Wed, 1 Jul 2020 15:46:14 +0200 Subject: [PATCH 12/21] Update 12_1_Verifying_Your_Tor_Setup.md --- 12_1_Verifying_Your_Tor_Setup.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/12_1_Verifying_Your_Tor_Setup.md b/12_1_Verifying_Your_Tor_Setup.md index 64e078e..1795da0 100644 --- a/12_1_Verifying_Your_Tor_Setup.md +++ b/12_1_Verifying_Your_Tor_Setup.md @@ -29,7 +29,17 @@ Output 2020-06-25T18:16:44Z tor: Thread interrupt 2020-06-25T19:11:12Z tor: Got service ID [YOUR_ONION_ID], advertising service your_onion_id.onion:8333 ``` -Using bitcoin-cli you should use: +Using bitcoin-cli you should use getnetworkinfo to get your onion id like this: + +``` + "localaddresses": [ + { + "address": "your_onion_id.onion", + "port": 8333, + "score": 4 + } + ], +``` ``` $ bitcoin-cli getnetworkinfo From 661eaf6a3e5252c2aaa9ab078b7e5f62984c90ad Mon Sep 17 00:00:00 2001 From: Javier Vargas Date: Wed, 1 Jul 2020 18:08:38 +0200 Subject: [PATCH 13/21] Update 12_2_Changing_Your_Bitcoin_Hidden_Services.md --- 12_2_Changing_Your_Bitcoin_Hidden_Services.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/12_2_Changing_Your_Bitcoin_Hidden_Services.md b/12_2_Changing_Your_Bitcoin_Hidden_Services.md index a882878..59c835b 100644 --- a/12_2_Changing_Your_Bitcoin_Hidden_Services.md +++ b/12_2_Changing_Your_Bitcoin_Hidden_Services.md @@ -13,6 +13,12 @@ Add your user to debian-tor group like this: ~$ sudo usermod -a -G debian-tor [CHANGE_MY_USER] ``` +If you're running a older version Tor like 0.2.7 add this lines to /etc/tor/torrc file: + +``` +HiddenServiceDir /var/lib/tor/bitcoin-service/ +HiddenServicePort 8333 127.0.0.1:8333 +HiddenServicePort 18333 127.0.0.1:18333 +``` +If you're running Tor version 3 bitcoind will configurate hidden services to listen on. - ll /run/tor/control.authcookie --rw-r----- 1 debian-tor debian-tor 32 jun 26 09:44 /run/tor/control.authcookie From e038f6376ec356fbdabdf1f8d43b149defd1d236 Mon Sep 17 00:00:00 2001 From: Javier Vargas Date: Wed, 1 Jul 2020 18:09:43 +0200 Subject: [PATCH 14/21] Update 12_2_Changing_Your_Bitcoin_Hidden_Services.md --- 12_2_Changing_Your_Bitcoin_Hidden_Services.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/12_2_Changing_Your_Bitcoin_Hidden_Services.md b/12_2_Changing_Your_Bitcoin_Hidden_Services.md index 59c835b..33ea475 100644 --- a/12_2_Changing_Your_Bitcoin_Hidden_Services.md +++ b/12_2_Changing_Your_Bitcoin_Hidden_Services.md @@ -20,5 +20,5 @@ HiddenServiceDir /var/lib/tor/bitcoin-service/ HiddenServicePort 8333 127.0.0.1:8333 HiddenServicePort 18333 127.0.0.1:18333 ``` -If you're running Tor version 3 bitcoind will configurate hidden services to listen on. +If you're running Tor version 3 bitcoind will configurate hidden services automatically to listen on. From e7f0bc278e0e1121e1fa9cc44a8ed20e0e727a29 Mon Sep 17 00:00:00 2001 From: Javier Vargas Date: Wed, 1 Jul 2020 18:13:20 +0200 Subject: [PATCH 15/21] Update 12_2_Changing_Your_Bitcoin_Hidden_Services.md --- 12_2_Changing_Your_Bitcoin_Hidden_Services.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/12_2_Changing_Your_Bitcoin_Hidden_Services.md b/12_2_Changing_Your_Bitcoin_Hidden_Services.md index 33ea475..7b73d7e 100644 --- a/12_2_Changing_Your_Bitcoin_Hidden_Services.md +++ b/12_2_Changing_Your_Bitcoin_Hidden_Services.md @@ -7,7 +7,13 @@ In this chapter we will show you how to create or change your local Bitcoin Hidd -rw-r----- 1 debian-tor debian-tor 32 jun 26 09:44 /run/tor/control.authcookie ``` -Add your user to debian-tor group like this: +To avoid see a message like this in debug log file you need to add your current user to debian-tor group like this: + +debug.log + +``` +2020-05-15T16:49:20Z tor: Authentication cookie /run/tor/control.authcookie could not be opened (check permissions) +``` ``` ~$ sudo usermod -a -G debian-tor [CHANGE_MY_USER] From e629b48481dca1c4140287074aa105af37aa09d0 Mon Sep 17 00:00:00 2001 From: Javier Vargas Date: Wed, 1 Jul 2020 18:45:08 +0200 Subject: [PATCH 16/21] Create 12_3_Adding_SSH_Hidden_Services --- 12_3_Adding_SSH_Hidden_Services | 50 +++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 12_3_Adding_SSH_Hidden_Services diff --git a/12_3_Adding_SSH_Hidden_Services b/12_3_Adding_SSH_Hidden_Services new file mode 100644 index 0000000..5e1a562 --- /dev/null +++ b/12_3_Adding_SSH_Hidden_Services @@ -0,0 +1,50 @@ +# Chapter 12.3: Adding SSH Hidden Services + +In this chapter we will show you how to add a ssh hidden service to login remotelly using tor. + +## Create SSH Hidden Services + +To create new service you need to add some lines in your torrcfile. + +This should be under /etc/tor/torrc + +Add this lines: + +``` +HiddenServiceDir /var/lib/tor/hidden-service-ssh/ +HiddenServicePort 22 127.0.0.1:22 +HiddenServiceAuthorizeClient stealth hidden-service-ssh +``` + +* HiddenServiceDir indicates tor that you have a hidden service directory with the neccesary configuration on path. +* HiddenServicePort indicates tor port to be used, in SSH case is 22, if you want use other port you can change here. +* HiddenServiceAuthorizeClient As it's name indicates authorize a client to connect to the hidden service. + +After add lines to tor file you need to restart tor service + +``` +sudo /etc/init.d/tor restart +``` + +After restart you should have three new files like this: + +``` +total 24 +drwx--S--- 3 debian-tor debian-tor 4096 jul 1 18:39 ./ +drwx--S--- 5 debian-tor debian-tor 4096 jul 1 18:39 ../ +drwx--S--- 2 debian-tor debian-tor 4096 jul 1 18:39 authorized_clients/ +-rw------- 1 debian-tor debian-tor 63 jul 1 18:39 hostname +-rw------- 1 debian-tor debian-tor 64 jul 1 18:39 hs_ed25519_public_key +-rw------- 1 debian-tor debian-tor 96 jul 1 18:39 hs_ed25519_secret_key +``` +The file hostname contains your id onion. + +Use this address to connect to your ssh hidden service like this: + +``` +torify ssh @your_new_onion_id.onion +``` + + + + From bedcf765a53244873876267993a51be186473d11 Mon Sep 17 00:00:00 2001 From: Javier Vargas Date: Wed, 1 Jul 2020 18:46:28 +0200 Subject: [PATCH 17/21] Update 12_0_Using_Tor.md --- 12_0_Using_Tor.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/12_0_Using_Tor.md b/12_0_Using_Tor.md index ac8086b..ad8fa68 100644 --- a/12_0_Using_Tor.md +++ b/12_0_Using_Tor.md @@ -6,4 +6,4 @@ This section will talk about using the Tor services that are now available court * [12.1: Verifying Your Tor Setup](12_1_Verifying_Your_Tor_Setup.md) * [12.2: Changing Your Bitcoin Hidden Services](12_2_Changing_Your_Bitcoin_Hidden_Services.md) - * 12.3: Adding SSH Hiddne Services + * [12.3: Adding SSH Hiddne Services](12_3_Adding_SSH_Hidden_Services) From 9439de608b7e9583a8d1354f102b182575f76ae9 Mon Sep 17 00:00:00 2001 From: Javier Vargas Date: Wed, 1 Jul 2020 18:46:41 +0200 Subject: [PATCH 18/21] Update 12_0_Using_Tor.md --- 12_0_Using_Tor.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/12_0_Using_Tor.md b/12_0_Using_Tor.md index ad8fa68..d8f97ec 100644 --- a/12_0_Using_Tor.md +++ b/12_0_Using_Tor.md @@ -6,4 +6,4 @@ This section will talk about using the Tor services that are now available court * [12.1: Verifying Your Tor Setup](12_1_Verifying_Your_Tor_Setup.md) * [12.2: Changing Your Bitcoin Hidden Services](12_2_Changing_Your_Bitcoin_Hidden_Services.md) - * [12.3: Adding SSH Hiddne Services](12_3_Adding_SSH_Hidden_Services) + * [12.3: Adding SSH Hidden Services](12_3_Adding_SSH_Hidden_Services) From 3e4ec41fab0838a5f9e1c176683f1348a1104cae Mon Sep 17 00:00:00 2001 From: Javier Vargas Date: Wed, 1 Jul 2020 18:47:30 +0200 Subject: [PATCH 19/21] Update 12_3_Adding_SSH_Hidden_Services --- 12_3_Adding_SSH_Hidden_Services | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/12_3_Adding_SSH_Hidden_Services b/12_3_Adding_SSH_Hidden_Services index 5e1a562..76b1d12 100644 --- a/12_3_Adding_SSH_Hidden_Services +++ b/12_3_Adding_SSH_Hidden_Services @@ -16,9 +16,9 @@ HiddenServicePort 22 127.0.0.1:22 HiddenServiceAuthorizeClient stealth hidden-service-ssh ``` -* HiddenServiceDir indicates tor that you have a hidden service directory with the neccesary configuration on path. -* HiddenServicePort indicates tor port to be used, in SSH case is 22, if you want use other port you can change here. -* HiddenServiceAuthorizeClient As it's name indicates authorize a client to connect to the hidden service. +* HiddenServiceDir: indicates tor that you have a hidden service directory with the neccesary configuration on path. +* HiddenServicePort: indicates tor port to be used, in SSH case is 22, if you want use other port you can change here. +* HiddenServiceAuthorizeClient: As it's name indicates authorize a client to connect to the hidden service. After add lines to tor file you need to restart tor service From 8d93aa2efcab8e153fba6c10e528d35b5e60267f Mon Sep 17 00:00:00 2001 From: Javier Vargas Date: Wed, 1 Jul 2020 18:50:08 +0200 Subject: [PATCH 20/21] Update and rename 12_3_Adding_SSH_Hidden_Services to 12_3_Adding_SSH_Hidden_Services.md --- ...SH_Hidden_Services => 12_3_Adding_SSH_Hidden_Services.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename 12_3_Adding_SSH_Hidden_Services => 12_3_Adding_SSH_Hidden_Services.md (89%) diff --git a/12_3_Adding_SSH_Hidden_Services b/12_3_Adding_SSH_Hidden_Services.md similarity index 89% rename from 12_3_Adding_SSH_Hidden_Services rename to 12_3_Adding_SSH_Hidden_Services.md index 76b1d12..d04735a 100644 --- a/12_3_Adding_SSH_Hidden_Services +++ b/12_3_Adding_SSH_Hidden_Services.md @@ -1,10 +1,10 @@ # Chapter 12.3: Adding SSH Hidden Services -In this chapter we will show you how to add a ssh hidden service to login remotelly using tor. +In this chapter we will show you how to add a ssh hidden service to login remotelly using Tor. ## Create SSH Hidden Services -To create new service you need to add some lines in your torrcfile. +To create new service you need to add some lines in your torrc file. This should be under /etc/tor/torrc @@ -16,7 +16,7 @@ HiddenServicePort 22 127.0.0.1:22 HiddenServiceAuthorizeClient stealth hidden-service-ssh ``` -* HiddenServiceDir: indicates tor that you have a hidden service directory with the neccesary configuration on path. +* HiddenServiceDir: indicates tor that you have a hidden service directory with the necessary configuration on path. * HiddenServicePort: indicates tor port to be used, in SSH case is 22, if you want use other port you can change here. * HiddenServiceAuthorizeClient: As it's name indicates authorize a client to connect to the hidden service. From f35b55cf98e096a94c53957794f4feb1488b6c4d Mon Sep 17 00:00:00 2001 From: Javier Vargas Date: Thu, 2 Jul 2020 12:43:08 +0200 Subject: [PATCH 21/21] Update 12_0_Using_Tor.md --- 12_0_Using_Tor.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/12_0_Using_Tor.md b/12_0_Using_Tor.md index d8f97ec..853ef5f 100644 --- a/12_0_Using_Tor.md +++ b/12_0_Using_Tor.md @@ -6,4 +6,4 @@ This section will talk about using the Tor services that are now available court * [12.1: Verifying Your Tor Setup](12_1_Verifying_Your_Tor_Setup.md) * [12.2: Changing Your Bitcoin Hidden Services](12_2_Changing_Your_Bitcoin_Hidden_Services.md) - * [12.3: Adding SSH Hidden Services](12_3_Adding_SSH_Hidden_Services) + * [12.3: Adding SSH Hidden Services](12_3_Adding_SSH_Hidden_Services.md)