bronze

Crates.iobronze
lib.rsbronze
version0.1.0
sourcesrc
created_at2016-03-11 04:48:57.459971
updated_at2016-03-11 04:48:57.459971
descriptionA rust coap server framework. (Early, but functional.)
homepage
repositoryhttps://github.com/azdle/bronze
max_upload_size
id4425
size28,264
Patrick Barrett (azdle)

documentation

README

Bronze

Build Status Crates.io Link

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
            }
        }
    }
}

Commit count: 28

cargo fmt