Rust proc macros - the experience of a noob

Who am I and what is this post about

Recently I started working professionally with Rust and it wasn't long before I stumbled upon proc macros. I had to make some changes to a relatively complex (for me) macro which generates traits and implementations for them. Reading about macros (and especially proc macros) in Rust created some associations with C++ metaprogramming which is not exactly my cup of tea. As a result I was determined not to enjoy the task. However it turned out that proc macros aren't that bad. They are very different from the regular Rust one sees every day but they are not black magic. And you can do useful stuff with them.

So why this post? There are a lot of resources for learning proc macros out there. I've read some of them but despite that there were things which just didn't click for me in the beginning. I needed something more to reach the 'now this makes sense' moment. So after gaining some knowledge I decided to write this post and share my experience. And more specifically - the things I didn't initially understand.

Should you read it? The short answer is NO :). If you aren't a complete proc macro newbie - there is nothing for you here. I'll be very grateful if you want to read it and share your feedback/advise. But don't be disappointed if you expect to learn something new and you only see obvious stuff. If you are just starting to learn proc macros this post might help. But people are different - hard things for me are maybe easy for you and the other way around.

Read more…

Brief Introduction to Crypto++

At some point in your life as a software engineer you will have to write code involving cryptography (crypto for short). You might need to implement a password authentication system by keeping salted password hashes for your users or add encryption for your custom binary protocol implementation or save some files securely on disk, etc. This is usually harder than it sounds and you will have to use some crypto library to get the job done.

In this post I want to write a really quick and short introduction to Crypto++, a C++ cryptographic library. My first experience with it led a lot of questions. Reading the documentation and googling answers took me some time so I want to share my experience. Hopefully you will find the information in this post helpful and will save you some time.

Read more…

The book is published!

Finally "SCTP in Theory and Practice" is ready. This is a really exciting moment for me. The book is available on Leanpub, but as I reader of my blog you can get 20% discount till the end of May 2020 by using this coupon.

/post-files/the-book-is-published/cover.jpg

What to expect compared to the blog posts: - Huge part of the text is rewritten to be easier to read, shorter (where possible) and with consistent style. - All the diagrams are changed with better looking ones. - Topics are rearranged in more logical order. - All the sample code from hands on chapters of the book is rewritten. This is the biggest change in the book. The essential client-server code is separated and as a result the code samples are shorter and easier to follow. - You can read the material offline in epub, mobi or PDF.

SCTP in Theory and Practice - my new e-book

I am glad to share that the e-book I wrote about in my last post is almost finished. I expected to finish it a lot faster as I already had the blog posts, but writing is not an easy job, especially when you do it for the first time. But luckily my book is almost ready and I will launch it on Leanpub by the end of the month.

EDIT (28.04.2020): The book is already published on Leanpub.

SCTP in Theory and Practice

This is the title of the book. It is around 120 pages long and contains 11 chapters which more or less follow the posts in this blog. You can see the page of the book on LeanPub here. You probably wonder what is changed? In nutshell:

  • Huge part of the text is rewritten to be easier to read, shorter (where possible) and with consistent style.
  • All the diagrams are changed with better looking ones.
  • Topics are rearranged in more logical order.
  • All the sample code from hands on chapters of the book is rewritten. Actually this is the biggest change in the book. The old code contained a lot of chunks which were needed but not related to SCTP. The new version has these parts reworked and separated from the essential SCTP client/server code. As a result the code samples are shorter and I hope easier to follow and understand.
  • And of course thanks to being an e-book you can read the material offline in epub, mobi or PDF.
  • In the previous post I promised to include unpublished bonus material in the book. Unfortunately the additional material I want to write about is still not good enough so I won't include it in the book.

At this point I don't plan paper version of the book. This is my first writing so probably I made some mistakes that I want to fix fast easy and free. Keeping the book in e-version only makes it easier to make fixes and add chapters on the go. And thanks to Leanpub you have to purchase the book only once and you will receive all updates for free afterwards.

Getting the book

You can purchase the book on Leanpub here.

My new project - a book about SCTP

A few people mentioned that there are not much resources about SCTP on the Internet besides my blog. This makes me just a little proud and a bit sad at the same time. SCTP is not at all popular but it is used a lot in the Telecom world and I believe it deserves its spot online. Looks like my posts sort of do the job, but it is not the best reading experience one can get. For this reason I decided to convert the posts to a book and in this post I want to share with you some details about it.

Why bother with writing a book? Posts do the job just fine?

This is probably true for the most of the people. However the posts are written from a developer for developers and they focus on the information. The style is bad, the graphics are mediocre at best. I want to take this content one step further and make it a nice read!

What will be in the book?

The book will include:

Will the content differ from the blog posts?

Yes and no. Most of the information will be the same, but it will be edited (and probably rearranged) so that it will be more consistent. Bottom line - almost the same information, presented in far better way!

Of course the unpublished content initially will be only in the book.

Hardcopy or e-book?

It will be an electronic book - PDF and EPUB version.

Okay, I want to know more. How can I stay in the loop?

I've created a newsteller on MailChimp and at this point it will be completely dedicated to the book. If you are interested - subscribe! I promise I won't spam you - you'll receive no more than one e-mail per week from me with news about the book, preview chapters, etc. You could even influence my work - I will involve the subscribers with any decisions I have to make during the writing.

If you want to help me, please spread the word about the book and share a link to the mail list. The more subscribers I get, more confident I am that my work is valued.

Click here to subscribe to the newsteller!

rpcap becomes tranqap

In my previous post I announced a project of mine which I use to collect PCAP files from remote machines. I will not go in too much details about it, if you are interested - check the blog post. I named the project rpcap (from remote pcap) and as it was for my personal use I didn't check if the name was not already used.

As you probably have already guessed, the name is used even for a project doing similar thing. I will not go into to much details about the original rpcap project either, so if you are interested - go check its website.

Long story short - I needed a new name. And it is tranqap. It comes from the French word tranquille (which means "calm, quiet, peaceful") and of course PCAP. I truly hope that this new name holds true for the real purpose of the project - to make network traffic captures tranquille.

Check out tranqap.com for the updated links to source code and documentation.

What is tranqap

EDIT: Initially this post was titled "What is rpcap". For reasons described here, I had to rename it. I will keep the original hyperlink, to avoid confusion, but all references to rpcap here will be replaced to tranqap.

Why this project exists

I used to work on an IMS project, which involved multiple machines. In nutshell, IMS stands for IP Multimedia Subsystem and it is a SIP based implementation of voice service in LTE mobile network. I don't want to explain what IMS is, as it is totally out of the scope of this post, but if you are interested the page for IMS in Wikipedia is a good start.

Tracing a voice call in an IMS setup involves packet capturing on four different machines, which turned out to be a pretty tedious job. Up to now, my work required to collect PCAP files from one or maximum two remote machines. To achieve this I used a simple bash script, which starts tcpdump over SSH and redirects the output to a Wireshark instance running locally. You can find the script in my dotfiles shared on GitHub.

Using this script for capturing traffic from four remote machines was not very straightforward. I often ended up forgetting to start the script for any of the machines, forget to save the file, close wireshark by mistake and so on.

At this point the idea for tranqap was born.

Read more…

Zodiac FX review

What is Zodiac FX

Zodiac FX is an OpenFlow enabled switch, developed by Northbound Networks. They promote it on their kickstarter project as:

The OpenFlow switch that is powerful enough to develop world changing SDN applications yet small enough to sit on your desk.

I've played with Openflow during Nick Feamster's course Software Defined Networking and I've decided that owning such device is a good opportunity to run Openflow controllers in a real network. I can't say how powerful the switch is, because all I have done up to now is to get it out of the box and start it up, but it is definitely small! Its dimensions are 10 x 8 cm, so expect something as big as Raspberry Pi, for example.

Read more…

SCTP Multi-homing in Linux

Introduction

After exploring how SCTP multi-homing works, it's time to see how to use this feature in Linux. This post will show how to implement multi-homing for the client-server application, used up to now. Baseline code for the development will be the 'one-to-many_advanced' branch, used in SCTP specific socket functions in Linux post. It already uses SCTP's advanced interface so only a few modifications are required to get the job done.

Implementing multi-homing means that the server should bind to more than one IP address and the client - to connect to more than one destination IP address. Both applications can also operate on single IP address. Mixed scenario is also possible, e.g. multi-homed server can communicate with non multi-homed client.

The code in this post uses one-to-many styles sockets, however the approach is the same for one-to-one sockets. I am pretty sure that you will be able to handle the latter case by yourself, so I will not discuss it. Anyway do not hesitate to leave a comment, in case you have got any questions.

Read more…

Multi-homing in SCTP

What is multihoming

In the previous posts about the SCTP protocol, I promised a separate article about multi-homing. I think we have covered most of the basic topics and now it is time to review this killer feature. The behaviour of a multi-homed SCTP node is scattered around RFC 4960 and in this post I will present the most important aspects.

I think Section 6.4 has got the best definition for multi-homing:

An SCTP endpoint is considered multi-homed if there are more than one transport address that can be used as a destination address to reach that endpoint.

Read more…