-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sascha Grunert
authored and
Sascha Grunert
committed
Dec 20, 2016
1 parent
81c5076
commit 4879bd1
Showing
3 changed files
with
38 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,22 @@ | ||
# peel [![Build Status](https://travis-ci.org/saschagrunert/peel.svg)](https://travis-ci.org/saschagrunert/peel) [![Build status](https://ci.appveyor.com/api/projects/status/i67yq6yij2k17iwc?svg=true)](https://ci.appveyor.com/project/saschagrunert/peel) [![Coverage Status](https://coveralls.io/repos/github/saschagrunert/peel/badge.svg?branch=master)](https://coveralls.io/github/saschagrunert/peel?branch=master) [![doc peel](https://img.shields.io/badge/doc-peel-blue.svg)](https://saschagrunert.github.io/peel) [![License MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/saschagrunert/peel/blob/master/LICENSE) | ||
## Dynamic packet parsing within trees 🌲 🌳 🌴 | ||
Target of this library is to provide a flexible parsing approach for network packets. This will be done within | ||
[arena](https://en.wikipedia.org/wiki/Region-based_memory_management) based [parser trees](https://en.wikipedia.org/wiki/Parse_tree) | ||
which can be modified during runtime. Other stacks beside the well known TCP/IP protocol family should be parsable too. | ||
# indextree [![Build Status](https://travis-ci.org/saschagrunert/indextree.svg)](https://travis-ci.org/saschagrunert/indextree) [![Build status](https://ci.appveyor.com/api/projects/status/byraapuh9py02us0?svg=true)](https://ci.appveyor.com/project/saschagrunert/indextree) [![Coverage Status](https://coveralls.io/repos/github/saschagrunert/indextree/badge.svg?branch=master)](https://coveralls.io/github/saschagrunert/indextree?branch=master) [![doc indextree](https://img.shields.io/badge/doc-indextree-blue.svg)](https://saschagrunert.github.io/indextree) [![License MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/saschagrunert/indextree/blob/master/LICENSE) | ||
## Arena based tree structure | ||
This arena tree structure is using just a single `Vec` and numerical identifiers (indices in the vector) instead of | ||
reference counted pointers like. This means there is no `RefCell` and mutability is handled in a way much more | ||
idiomatic to Rust through unique (&mut) access to the arena. The tree can be sent or shared across threads like a `Vec`. | ||
This enables general multiprocessing support like parallel tree traversals. | ||
|
||
### Example usage | ||
```rust | ||
use peel::prelude::*; | ||
use indextree::Arena; | ||
|
||
// Get the default tree based on the TCP/IP stack | ||
let peel = peel_tcp_ip(); | ||
// Create a new arena | ||
let arena = &mut Arena::new(); | ||
|
||
let eth_header = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 8, 0]; | ||
// Add some new nodes to the arena | ||
let a = arena.new_node(1); | ||
let b = arena.new_node(2); | ||
|
||
// Traverse the parser tree. If a parser matches check for available child parsers. | ||
// Stop parsing if there are no childs left. The `vec![]` memory will be used for | ||
// the resulting stack of `Layer`s. | ||
let result = peel.traverse(ð_header, vec![]).unwrap(); | ||
|
||
// There should be one parsed EthernetPacket in: | ||
assert_eq!(result.len(), 1); | ||
// Append a to b | ||
a.append(b, arena); | ||
assert_eq!(b.ancestors(arena).into_iter().count(), 2); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
extern crate indextree; | ||
use indextree::Arena; | ||
|
||
use indextree::*; | ||
use std::cell::Cell; | ||
|
||
#[test] | ||
|