<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Frank Horvath</title>
    <description>The latest articles on DEV Community by Frank Horvath (@frankhorv).</description>
    <link>https://dev.to/frankhorv</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1005220%2Fac631c7b-abe0-4e96-9bdf-3e4060da4812.png</url>
      <title>DEV Community: Frank Horvath</title>
      <link>https://dev.to/frankhorv</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/frankhorv"/>
    <language>en</language>
    <item>
      <title>An Open Source Rust SNMP Simulator</title>
      <dc:creator>Frank Horvath</dc:creator>
      <pubDate>Tue, 10 Jan 2023 09:35:01 +0000</pubDate>
      <link>https://dev.to/sonalake/an-open-source-rust-snmp-simulator-5e73</link>
      <guid>https://dev.to/sonalake/an-open-source-rust-snmp-simulator-5e73</guid>
      <description>&lt;p&gt;In much of the work we carry out for communication service providers (&lt;a href="https://en.wikipedia.org/wiki/Telephone_company"&gt;CSPs&lt;/a&gt;), either as part of &lt;a href="https://sonalake.com/telecom-solutions/visimetrix"&gt;VisiMetrix&lt;/a&gt; integrations or when developing custom software products, we need to integrate with IP networking devices that power the packet core, circuit-switched core, backhaul, transmission, &lt;a href="https://en.wikipedia.org/wiki/Radio_access_network"&gt;radio access&lt;/a&gt;, and &lt;a href="https://en.wikipedia.org/wiki/IP_Multimedia_Subsystem"&gt;IMS&lt;/a&gt; networks. While many of these integrations use proprietary management protocols, others conveniently use &lt;a href="https://en.wikipedia.org/wiki/Simple_Network_Management_Protocol"&gt;SNMP&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;SNMP defines a standard protocol to collect status data, configuration information, and asynchronous notifications from such devices. Slightly less convenient is the fact that during development, we often don’t have access to the actual devices we need to integrate.&lt;/p&gt;

&lt;p&gt;Developing and testing against production devices is not an option. While sometimes clients may have test devices, they’re often in high demand for exclusive access by other departments within the CSP. They can also suffer from sporadic downtime or are hidden behind remote desktop solutions rendering them unreachable from development and continuous integration environments.&lt;/p&gt;

&lt;p&gt;For these reasons, a very long time ago, we developed an SNMP agent simulator. We used &lt;a href="https://dev.java/"&gt;Java&lt;/a&gt; because it was our go-to language at the time. Cut to today, and while we still do most of our server-side work in &lt;a href="https://dev.java/"&gt;Java&lt;/a&gt; and &lt;a href="https://kotlinlang.org/"&gt;Kotlin&lt;/a&gt;, we also have a growing number of teams developing products for our clients in &lt;a href="https://www.rust-lang.org/"&gt;Rust&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Recently when looking for a way to provide more of our engineers an opportunity to develop and hone their Rust skills and hit on the idea of rewriting the agent simulator in Rust. Not only that, we decided to develop it in the &lt;a href="https://github.com/sonalake/snmp-sim-rust"&gt;open&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We’ll be sharing more about our progress in future posts, but in this one I’m going to talk about a particular challenge we hit early on.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem
&lt;/h2&gt;

&lt;p&gt;Our goal is to implement a service that can simulate one or more SNMP agents concurrently and allow such agents to be created, deleted, started, or stopped at runtime.&lt;/p&gt;

&lt;p&gt;Our functional requirements can be summarised as:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Expose REST endpoints that allow clients to control the simulator&lt;/li&gt;
&lt;li&gt;Support multiple UDP listeners, each on their own port&lt;/li&gt;
&lt;li&gt;Support dynamically creating and destroying UDP listeners&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We also want to avoid excessive thread creation.&lt;/p&gt;

&lt;p&gt;One of the first problems we hit was how to approach handling a dynamic set of UDP listeners in addition to a HTTP listener for REST API requests. Here’s what the (very) high level architecture looks like.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rwvmecy2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bwt6r0f931d2p5p33ytu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rwvmecy2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bwt6r0f931d2p5p33ytu.png" alt="SNMP simulator diagram" width="357" height="341"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;While there are plenty of Rust HTTP server frameworks [1], none support our UDP requirement. What to do?&lt;/p&gt;

&lt;h2&gt;
  
  
  Standing on the Shoulders of Giants
&lt;/h2&gt;

&lt;p&gt;Before we did anything, we needed to make some key technical decisions. Based on previous experience and in some cases research, we settled on using the following crates [2].&lt;/p&gt;

&lt;h3&gt;
  
  
  Actix
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/actix/actix"&gt;Actix&lt;/a&gt; is an &lt;a href="https://en.wikipedia.org/wiki/Actor_model"&gt;actor framework&lt;/a&gt; for developing concurrent applications built on top of the &lt;a href="https://tokio.rs/"&gt;Tokio&lt;/a&gt; asynchronous runtime. It allows multiple actors to run on a single thread, but also allows actors to run on multiple threads via &lt;a href="https://actix.rs/book/actix/sec-5-arbiter.html"&gt;Arbiters&lt;/a&gt;. Actors can communicate with each other by sequentially exchanging typed messages.&lt;/p&gt;

&lt;p&gt;The Actix framework is stable and mature and will ultimately help us create a scalable solution.&lt;/p&gt;

&lt;h2&gt;
  
  
  Actix Web
&lt;/h2&gt;

&lt;p&gt;To handle REST API requests, we chose the &lt;a href="https://actix.rs/)"&gt;Actix Web framework&lt;/a&gt;. By default, its &lt;a href="https://actix.rs/docs/server/"&gt;HttpServer&lt;/a&gt; automatically starts a number of HTTP workers equal to the number of logical CPUs in the system. Once created, each receives a separate application instance to handle requests. &lt;/p&gt;

&lt;p&gt;To handle REST API requests, we chose the Actix Web framework. By default, its HttpServer automatically starts a number of HTTP workers equal to the number of logical CPUs in the system. Once created, each receives a separate application instance to handle requests. Application state is not shared between threads, and handlers are free to manipulate their copy of the state with no concurrency concerns.&lt;/p&gt;

&lt;h3&gt;
  
  
  rasn ASN.1
&lt;/h3&gt;

&lt;p&gt;We also need to read and write SNMP messages. The &lt;a href="https://github.com/XAMPPRocky/rasn"&gt;rasn&lt;/a&gt; ASN.1 codec framework supports handling ASN.1 data types according to different encoding rules.&lt;/p&gt;

&lt;p&gt;Conveniently, it also provides implementations for a bunch of relevant SNMP IETF RFCs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;SNMP v1: &lt;a href="https://www.rfc-editor.org/rfc/rfc1157"&gt;RFC 1157&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;SNMP v2: &lt;a href="https://www.rfc-editor.org/rfc/rfc3416"&gt;RFC 3416&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;SNMP v2c: &lt;a href="https://dev.toRFC%201901"&gt;RFC 1901&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;SNMP v3: &lt;a href="https://www.rfc-editor.org/rfc/rfc3412"&gt;RFC 3412&lt;/a&gt;, &lt;a href="https://www.rfc-editor.org/rfc/rfc3414"&gt;RFC 3414&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Application Architecture
&lt;/h2&gt;

&lt;p&gt;On startup, the SNMP Agent Simulator creates a number of &lt;a href="https://github.com/sonalake/snmp-sim-rust/blob/8aa1d8ad4098bcd672861098192597d686445e36/src/udp_server/udp_server_provider.rs"&gt;UdpServerProvider&lt;/a&gt; actors to handle incoming requests. The number of actors is determined by the host environment CPU resources. The UdpStreamHandler actor is responsible for serializing and deserializing UDP messages and for forwarding the decoded SNMP messages to the SNMPAgentEngine for further processing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vSEkT5-N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1zuibnipgcyj9c852i9f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vSEkT5-N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1zuibnipgcyj9c852i9f.png" alt="SNMP Simulator architecture diagram" width="880" height="564"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  UDP Socket Creation
&lt;/h3&gt;

&lt;p&gt;So how do we go about creating a UDP socket for each agent? There are a couple of potential options. We can either use &lt;a href="https://doc.rust-lang.org/stable/std/net/struct.UdpSocket.html"&gt;UdpSocket&lt;/a&gt; from the Rust standard library, or &lt;a href="https://docs.rs/async-std/latest/async_std/net/struct.UdpSocket.html"&gt;UdpSocket&lt;/a&gt; from the Rust async standard library, or UdpSocket from Tokio. Which to choose?&lt;/p&gt;

&lt;h4&gt;
  
  
  Rust Standard Library
&lt;/h4&gt;

&lt;p&gt;The standard net &lt;a href="https://doc.rust-lang.org/std/net/struct.UdpSocket.html"&gt;UdpSocket&lt;/a&gt; represents a raw UDP socket bound to a socket address.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;std_socket&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;net&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;UdpSocket&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;binding_address&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;.map_err&lt;/span&gt;&lt;span class="p"&gt;(|&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="nn"&gt;UdpServerError&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;StartFailed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="nf"&gt;.to_string&lt;/span&gt;&lt;span class="p"&gt;()))&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Standard net UdpSockets are created in blocking mode by default, and adding a stream backed by a socket created in blocking mode to an Actix stream handler actor leads the actor to end up in deadlock state.&lt;/p&gt;

&lt;p&gt;To work around this, we need to ensure we create the socket in non-blocking mode before adding it to the Actix stream handler actor.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="n"&gt;std_socket&lt;/span&gt;
    &lt;span class="nf"&gt;.set_nonblocking&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;.map_err&lt;/span&gt;&lt;span class="p"&gt;(|&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="nn"&gt;UdpServerError&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;StartFailed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="nf"&gt;.to_string&lt;/span&gt;&lt;span class="p"&gt;()))&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From here we can take that socket and wrap it in a Tokio &lt;a href="https://docs.rs/tokio-util/latest/tokio_util/udp/struct.UdpFramed.html"&gt;UdpFramed&lt;/a&gt; object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;socket&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;TokioUdpSocket&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from_std&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;std_socket&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;.map_err&lt;/span&gt;&lt;span class="p"&gt;(|&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="nn"&gt;UdpServerError&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;StartFailed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="nf"&gt;.to_string&lt;/span&gt;&lt;span class="p"&gt;()))&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This works, but we have to explicitly set the socket to no-blocking mode. Perhaps the Rust async standard library might offer a solution.&lt;/p&gt;

&lt;h4&gt;
  
  
  Rust Async Standard Library
&lt;/h4&gt;

&lt;p&gt;Unfortunately this isn’t an option. Tokio does not support &lt;a href="https://docs.rs/async-std/latest/async_std/"&gt;async_std&lt;/a&gt; sockets so we can’t wrap the socket in a &lt;a href="https://docs.rs/tokio-util/latest/tokio_util/udp/struct.UdpFramed.html"&gt;UdpFramed&lt;/a&gt; object.&lt;/p&gt;

&lt;p&gt;The last option to explore is the Tokio UdpSocket.&lt;/p&gt;

&lt;h4&gt;
  
  
  Tokio UdpSocket
&lt;/h4&gt;

&lt;p&gt;The Tokio UdpSocket is created in non-blocking mode directly, so we don’t need to change that property manually.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;socket&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;TokioUdpSocket&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;binding_address&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;.await&lt;/span&gt;
    &lt;span class="nf"&gt;.map_err&lt;/span&gt;&lt;span class="p"&gt;(|&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="nn"&gt;UdpServerError&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;StartFailed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="nf"&gt;.to_string&lt;/span&gt;&lt;span class="p"&gt;()))&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This does the job and is succinct. Now that we’ve settled on how to create sockets, the next challenge is to figure out how to convert data to and from SNMP messages.&lt;/p&gt;

&lt;h3&gt;
  
  
  UDP data to SNMP Messages
&lt;/h3&gt;

&lt;p&gt;Raw UDP sockets work with &lt;a href="https://en.wikipedia.org/wiki/Datagram"&gt;datagrams&lt;/a&gt; (byte buffers), but it is more convenient for us to work with domain specific types (messages). Tokio &lt;a href="https://docs.rs/tokio-util/latest/tokio_util/udp/struct.UdpFramed.html"&gt;UdpFramed&lt;/a&gt; is an interface to an underlying UDP socket that returns a single object that is both a &lt;a href="https://docs.rs/futures-core/latest/futures_core/stream/trait.Stream.html"&gt;Stream&lt;/a&gt; for reading messages and a &lt;a href="https://docs.rs/futures-sink/latest/futures_sink/trait.Sink.html"&gt;Sink&lt;/a&gt; for writing messages. However, the StreamHandler actor expects the Stream part of the UdpFramed object only. Conveniently, the split method allows us to &lt;a href="https://docs.rs/futures-util/latest/futures_util/stream/trait.StreamExt.html#method.split"&gt;split&lt;/a&gt; the UdpFramed object into separate Stream and Sink objects as in the following code snippet.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c1"&gt;// create a UdpFramed object using the SnmpCodec to work with the encoded/decoded frames directly, instead of raw UDP data&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sink&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stream&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;UdpFramed&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nn"&gt;SnmpCodec&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;default&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;&lt;span class="nf"&gt;.split&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The UdpFramed constructor must be supplied by an instance of a codec object, which implements the &lt;a href="https://docs.rs/tokio-util/latest/tokio_util/codec/trait.Encoder.html"&gt;Encoder&lt;/a&gt; and &lt;a href="https://docs.rs/tokio-util/latest/tokio_util/codec/trait.Decoder.html"&gt;Decoder&lt;/a&gt; Tokio crate traits. It’s used on top of the socket to handle frames. SnmpCodec is used to decode the received UDP socket data into a stream of SNMP messages, and to encode the SNMP messages into ASN.1 encoded UDP socket data. The SnmpCodec is a wrapper of &lt;a href="https://github.com/XAMPPRocky/rasn"&gt;rasn&lt;/a&gt; ASN.1 codec framework, which implements the Encoder and Decoder traits to encode and decode UDP frames. The decoder and encoder implementations leverage the rasn ASN.1 codec framework.&lt;/p&gt;

&lt;p&gt;In the Actix &lt;a href="https://actix.rs/actix/actix/trait.StreamHandler.html#"&gt;StreamHandler&lt;/a&gt; actor, the stream handler helper trait is used to implement a UDP receiver data handler in a similar way to standard actor messages. The UdpStreamHandler represents an UDP socket receiver. The actor UdpMessage handler is called, when an SNMP message is received from the socket and successfully decoded.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Add the stream to the actor's context.&lt;/span&gt;
&lt;span class="c1"&gt;// Stream item will be treated as a concurrent message and the actor's handle will be called.&lt;/span&gt;
&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="nf"&gt;.add_stream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stream&lt;/span&gt;&lt;span class="nf"&gt;.map&lt;/span&gt;&lt;span class="p"&gt;(|&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="nf"&gt;UdpMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="nf"&gt;.map_err&lt;/span&gt;&lt;span class="p"&gt;(|&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="nf"&gt;.to_string&lt;/span&gt;&lt;span class="p"&gt;()))));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The StreamHandler actor has no method to deregister the stream from the actor’s context. The solution here is to simply close the socket representing the stream.&lt;/p&gt;

&lt;h2&gt;
  
  
  What next?
&lt;/h2&gt;

&lt;p&gt;We love Rust! It’s a great language. However, it’s still possible for developers to write code that results in deadlocks. This often happens when the synchronous and asynchronous worlds accidentally collide. Perhaps we’ll write more about that in a future post.&lt;/p&gt;

&lt;p&gt;In the meantime there’s lots more work to do on the SNMP simulator. If you’re interested in contributing, please let us know on &lt;a href="https://github.com/sonalake/snmp-sim-rust"&gt;Github&lt;/a&gt;!&lt;/p&gt;




&lt;p&gt;[1]: For example &lt;a href="https://actix.rs/"&gt;Actix Web&lt;/a&gt;, &lt;a href="https://rocket.rs/"&gt;Rocket&lt;/a&gt;, &lt;a href="https://github.com/tokio-rs/axum"&gt;Axum&lt;/a&gt;, &lt;a href="https://github.com/seanmonstar/warp"&gt;Warp&lt;/a&gt;, &lt;a href="https://github.com/http-rs/tide"&gt;Tide&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;[2]: 'Library' or 'package' for readers new to Rust &lt;/p&gt;

</description>
      <category>rust</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
