-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic, introductory examples for use
- Loading branch information
1 parent
caba7a1
commit d8fb714
Showing
10 changed files
with
98 additions
and
1 deletion.
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
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 |
---|---|---|
|
@@ -42,7 +42,7 @@ Fork or clone the main git repository: | |
|
||
`git clone [email protected]:stanford-esrg/retina.git` | ||
|
||
Write your first Retina application (see [examples](https://github.com/stanford-esrg/retina/tree/main/examples) and [documentation](https://stanford-esrg.github.io/retina/retina_core/index.html)). | ||
Write your first Retina application (see [examples](https://github.com/stanford-esrg/retina/tree/main/examples); `basic` and `basic_file` are good starters). | ||
|
||
Writing a Retina application consists of defining one or more subscriptions. A subscription is defined by (1) [writing a filter](https://stanford-esrg.github.io/retina/retina_filtergen/index.html) to describe what subset of network traffic you're interested in, (2) choosing [data types to subscribe to](https://stanford-esrg.github.io/retina/retina_datatypes/index.html), and (3) defining a callback function that takes in a subscribable data type and performs operations on the filtered, delivered data. | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "basic" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
env_logger = "0.8.4" | ||
retina-core = { path = "../../core" } | ||
retina-filtergen = { path = "../../filtergen" } | ||
retina-datatypes = { path = "../../datatypes" } | ||
lazy_static = "1.4.0" | ||
serde = { version = "1.0", features = ["derive"] } | ||
regex = "1.7.3" |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Basic | ||
|
||
An introductory example that logs TLS and DNS transactions, each with associated connection metrics. |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use retina_core::{config::default_config, Runtime}; | ||
use retina_datatypes::{ConnRecord, DnsTransaction, TlsHandshake}; | ||
use retina_filtergen::{filter, retina_main}; | ||
|
||
#[filter("tls")] | ||
fn tls_cb(tls: &TlsHandshake, conn_record: &ConnRecord) { | ||
println!("Tls SNI: {}, conn. metrics: {:?}", tls.sni(), conn_record); | ||
} | ||
|
||
#[filter("dns")] | ||
fn dns_cb(dns: &DnsTransaction, conn_record: &ConnRecord) { | ||
println!( | ||
"DNS query domain: {}, conn. metrics: {:?}", | ||
dns.query_domain(), | ||
conn_record | ||
); | ||
} | ||
|
||
#[retina_main(2)] | ||
fn main() { | ||
let config = default_config(); | ||
let mut runtime: Runtime<SubscribedWrapper> = Runtime::new(config, filter).unwrap(); | ||
runtime.run(); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "basic_file" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
env_logger = "0.8.4" | ||
retina-core = { path = "../../core" } | ||
retina-filtergen = { path = "../../filtergen" } | ||
retina-datatypes = { path = "../../datatypes" } | ||
lazy_static = "1.4.0" | ||
serde = { version = "1.0", features = ["derive"] } | ||
regex = "1.7.3" |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Basic (from specification TOML file) | ||
|
||
Basic application demonstrating the from-TOML file interface. Logs TLS handshakes matching certain SNIs to a file. |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[[subscriptions]] | ||
filter = "tls.sni ~ '^.*\\.com$'" | ||
datatypes = [ | ||
"TlsHandshake", | ||
"FilterStr", | ||
] | ||
callback = "tls_cb" | ||
|
||
[[subscriptions]] | ||
filter = "tls.sni ~ '^.*\\.net$'" | ||
datatypes = [ | ||
"TlsHandshake", | ||
"FilterStr", | ||
] | ||
callback = "tls_cb" | ||
|
||
[[subscriptions]] | ||
filter = "tls.sni ~ '^.*\\.edu$'" | ||
datatypes = [ | ||
"TlsHandshake", | ||
"FilterStr", | ||
] | ||
callback = "tls_cb" |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use retina_core::{config::default_config, Runtime}; | ||
use retina_datatypes::{FilterStr, TlsHandshake}; | ||
use retina_filtergen::subscription; | ||
|
||
fn tls_cb(tls: &TlsHandshake, filter_str: &FilterStr) { | ||
println!("Matched filter {}: {:?}", filter_str, tls); | ||
} | ||
|
||
#[subscription("./examples/basic_file/spec.toml")] | ||
fn main() { | ||
let config = default_config(); | ||
let mut runtime: Runtime<SubscribedWrapper> = Runtime::new(config, filter).unwrap(); | ||
runtime.run(); | ||
} |
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