#coap-server #server-framework #early #functional

bin+lib bronze

A rust coap server framework. (Early, but functional.)

1 unstable release

Uses old Rust 2015

0.1.0 Mar 11, 2016

#22 in #coap-server

32 downloads per month

MIT/Apache

29KB
760 lines

Bronze

Build Status

Bronze is a CoAP framework generally aimed at making high performance CoAP servers. It's not currently intended for use on especially resource constrained devices, but that is a long-term goal.

Bronze is written using mio for all network requests, this means that it has very low overheads

Status

Bronze is incomplete and you likely shouldn't use it.

Currently it is possible to create servers that directly deal with incoming CoAP packets, but there is not yet any automatic handling of retries or multi-packet messages.

There is not yet any implementation of client requests.

Getting Started

To use Bronze, add the following to your Cargo.toml:

[dependencies]
bronze = "0.1"

Then you'll need to create a run the server, a simple example of this would be:

extern crate bronze;

use bronze::endpoint::Endpoint;
use bronze::nullserver::NullServer;

fn main() {
    let local_addr = "127.0.0.1:5683".parse().unwrap();
    println!("CoAP Server Listening on {}", local_addr);
    Endpoint::new(local_addr).run(NullServer);
}

This example uses the included NullServer which is an example of how to write a request handler. NullServer simply replies to all valid CoAP packets with RST messages. It's implemented with:

use message::*;
use endpoint::RequestHandler;

use std::net::SocketAddr;

pub struct NullServer;

impl RequestHandler for NullServer {
    fn handle_request(&self, _addr: SocketAddr, in_pkt: &[u8]) -> Option<Vec<u8>> {
        //verify it's a real coap packet
        match Message::from_bin(in_pkt) {
            // is coap, reply with Reset
            // todo: would it be better to use an ack w/ error code?
            Ok(request) => {
                let reply = Message{
                    version: 1,
                    mtype: Mtype::Reset,
                    code: Code::Empty,
                    mid: request.mid,
                    token: request.token.clone(),
                    options: vec![],
                    payload: vec![]
                };

                Some(reply.as_bin().unwrap())
            },
            // not coap, ignore (prevents participating in reflection attacks)
            Err(_) => {
                None
            }
        }
    }
}

Dependencies

~3.5MB
~68K SLoC