Skip to content

Commit 16c7f1c

Browse files
committed
docs: add readmes for individual crates
So they show up on crates.io.
1 parent 963c08f commit 16c7f1c

File tree

4 files changed

+100
-3
lines changed

4 files changed

+100
-3
lines changed

README.md

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
[![Build status](https://github.com/ystreet/stun-proto/workflows/Build/badge.svg?branch=master)](https://github.com/ystreet/stun-proto/actions)
2-
[![codecov](https://codecov.io/gh/ystreet/stun-proto/branch/main/graph/badge.svg?token=7SP9REUN7L)](https://codecov.io/gh/ystreet/stun-proto)
1+
[![Build status](https://github.com/ystreet/stun-proto/actions/workflows/rust.yml/badge.svg?branch=main)](https://github.com/ystreet/stun-proto/actions)
2+
[![codecov](https://codecov.io/gh/ystreet/stun-proto/branch/main/graph/badge.svg)](https://codecov.io/gh/ystreet/stun-proto)
33
[![Dependencies](https://deps.rs/repo/github/ystreet/stun-proto/status.svg)](https://deps.rs/repo/github/ystreet/stun-proto)
44
[![crates.io](https://img.shields.io/crates/v/stun-proto.svg)](https://crates.io/crates/stun-proto)
55
[![docs.rs](https://docs.rs/stun-proto/badge.svg)](https://docs.rs/stun-proto)
@@ -13,4 +13,17 @@ the [Rust programming language](https://www.rust-lang.org/).
1313

1414
- [RFC5389](https://tools.ietf.org/html/rfc5389):
1515
Session Traversal Utilities for NAT (STUN)
16+
- [RFC8489](https://tools.ietf.org/html/rfc8489):
17+
Session Traversal Utilities for NAT (STUN)
18+
19+
## Structure
20+
21+
### [stun-types](https://github.com/ystreet/stun-proto/tree/main/stun-types)
22+
23+
Contains parsers and writing implementations for STUN messages and attributes.
24+
25+
### [stun-proto](https://github.com/ystreet/stun-proto/tree/main/stun-proto)
1626

27+
`stun-proto` builds on top of `stun-types` and implements some of the
28+
STUN protocol requirements when communicating with a peer. It does this using a
29+
sans-IO API and thus does no networking calls of its own.

stun-proto/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[![Build status](https://github.com/ystreet/stun-proto/actions/workflows/rust.yml/badge.svg?branch=main)](https://github.com/ystreet/stun-proto/actions)
2+
[![codecov](https://codecov.io/gh/ystreet/stun-proto/branch/main/graph/badge.svg)](https://codecov.io/gh/ystreet/stun-proto)
3+
[![Dependencies](https://deps.rs/repo/github/ystreet/stun-proto/status.svg)](https://deps.rs/repo/github/ystreet/stun-proto)
4+
[![crates.io](https://img.shields.io/crates/v/stun-proto.svg)](https://crates.io/crates/stun-proto)
5+
[![docs.rs](https://docs.rs/stun-proto/badge.svg)](https://docs.rs/stun-proto)
6+
7+
# stun-proto
8+
9+
Repository containing a sans-IO implementation of the STUN (RFC5389/RFC8489) protocol written in
10+
the [Rust programming language](https://www.rust-lang.org/).
11+
12+
## Relevant standards
13+
14+
- [RFC5389](https://tools.ietf.org/html/rfc5389):
15+
Session Traversal Utilities for NAT (STUN)
16+
- [RFC8489](https://tools.ietf.org/html/rfc8489):
17+
Session Traversal Utilities for NAT (STUN)
18+

stun-proto/src/agent.rs

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
// except according to those terms.
88

99
//! STUN agent
10+
//!
11+
//! A STUN Agent that follows the procedures of [RFC5389] and [RFC8489] and is implemented with the
12+
//! sans-IO pattern. This agent does no IO processing and operates solely on inputs it is
13+
//! provided.
14+
//!
15+
//! [RFC8489]: https://tools.ietf.org/html/rfc8489
16+
//! [RFC5389]: https://tools.ietf.org/html/rfc5389
1017
1118
use std::net::SocketAddr;
1219
use std::sync::atomic::{AtomicUsize, Ordering};

stun-proto/src/lib.rs

+60-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,68 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9+
//! # stun-proto
10+
//!
11+
//! A sans-IO implementation of a STUN agent as specified in [RFC5389] and [RFC8489].
12+
//!
13+
//! [RFC8489]: https://tools.ietf.org/html/rfc8489
14+
//! [RFC5389]: https://tools.ietf.org/html/rfc5389
15+
//!
16+
//! ## Example
17+
//!
18+
//! ```
19+
//! # use std::net::SocketAddr;
20+
//! use stun_proto::types::TransportType;
21+
//! use stun_proto::types::attribute::{MessageIntegrity, XorMappedAddress};
22+
//! use stun_proto::types::message::{
23+
//! BINDING, IntegrityAlgorithm, Message, MessageIntegrityCredentials, ShortTermCredentials
24+
//! };
25+
//! use stun_proto::agent::{HandleStunReply, StunAgent};
26+
//! let local_addr = "10.0.0.1:12345".parse().unwrap();
27+
//! let remote_addr = "10.0.0.2:3478".parse().unwrap();
28+
//!
29+
//! let mut agent = StunAgent::builder(TransportType::Udp, local_addr).build();
30+
//!
31+
//! // short term or short term credentials may optionally be configured on the agent.
32+
//! let local_credentials = ShortTermCredentials::new(String::from("local_password"));
33+
//! let remote_credentials = ShortTermCredentials::new(String::from("remote_password"));
34+
//! agent.set_local_credentials(local_credentials.clone().into());
35+
//! agent.set_remote_credentials(remote_credentials.clone().into());
36+
//!
37+
//! // and we can send a Message
38+
//! let mut msg = Message::new_request(BINDING);
39+
//! msg.add_message_integrity(&local_credentials.clone().into(), IntegrityAlgorithm::Sha1).unwrap();
40+
//! let transmit = agent.send(msg, remote_addr).unwrap();
41+
//!
42+
//! // The transmit struct indicates what data and where to send it.
43+
//! let request = Message::from_bytes(&transmit.data).unwrap();
44+
//!
45+
//! let mut response = Message::new_success(&request);
46+
//! let xor_addr = XorMappedAddress::new(transmit.from, request.transaction_id());
47+
//! response.add_attribute(xor_addr).unwrap();
48+
//! response.add_message_integrity(&remote_credentials.clone().into(), IntegrityAlgorithm::Sha1).unwrap();
49+
//!
50+
//! // when receiving data on the associated socket, we should pass it through the Agent so it can
51+
//! // parse and handle any STUN messages.
52+
//! let data = response.to_bytes();
53+
//! let to = transmit.to;
54+
//! let reply = agent.handle_incoming_data(&data, to).unwrap();
55+
//!
56+
//! // If running over TCP then there may be multiple messages parsed. However UDP will only ever
57+
//! // have a single message per datagram.
58+
//! assert!(matches!(reply[0], HandleStunReply::StunResponse(_, _)));
59+
//!
60+
//! // Once valid STUN data has been sent and received, then data can be sent and received from the
61+
//! // peer.
62+
//! let data = vec![42; 8];
63+
//! let transmit = agent.send_data(&data, remote_addr);
64+
//! assert_eq!(transmit.data(), &data);
65+
//! assert_eq!(transmit.from, local_addr);
66+
//! assert_eq!(transmit.to, remote_addr);
67+
//! ```
68+
969
pub mod agent;
1070

11-
// reexport stun_types;
1271
pub use stun_types as types;
1372

1473
#[derive(Clone)]

0 commit comments

Comments
 (0)