Skip to content
This repository was archived by the owner on Aug 15, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
# Pre-commit hook to run cargo fmt

echo "Running cargo fmt..."

# Check if cargo is available
if ! command -v cargo &> /dev/null; then
echo "cargo could not be found. Please install Rust."
exit 1
fi

# Run cargo fmt in check mode
if ! cargo fmt -- --check; then
echo ""
echo "Code formatting issues detected!"
echo "Please run 'cargo fmt' to fix formatting before committing."
echo ""
exit 1
fi

echo "Formatting check passed!"
exit 0
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,22 @@ int main() {

Contributions are welcome! Please feel free to open an issue or submit a pull request.

### Setting Up Git Hooks

This project uses git hooks to ensure code quality. To set up the pre-commit hook that runs `cargo fmt`:

**On Unix/Linux/macOS:**
```bash
./setup-hooks.sh
```

**On Windows:**
```cmd
setup-hooks.bat
```

This will configure git to run `cargo fmt --check` before each commit, ensuring all code is properly formatted.

## License

This project is licensed under the MIT License.
13 changes: 13 additions & 0 deletions setup-hooks.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@echo off
REM Script to set up git hooks for the project on Windows

echo Setting up git hooks...

REM Configure git to use the .githooks directory
git config core.hooksPath .githooks

echo.
echo Git hooks configured successfully!
echo The pre-commit hook will now run 'cargo fmt --check' before each commit.
echo.
echo To bypass the hook (not recommended), use: git commit --no-verify
12 changes: 12 additions & 0 deletions setup-hooks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
# Script to set up git hooks for the project

echo "Setting up git hooks..."

# Configure git to use the .githooks directory
git config core.hooksPath .githooks

echo "Git hooks configured successfully!"
echo "The pre-commit hook will now run 'cargo fmt --check' before each commit."
echo ""
echo "To bypass the hook (not recommended), use: git commit --no-verify"
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub use error::{Result, TransportServicesError};
pub use framer::{Framer, FramerStack, LengthPrefixFramer};
pub use listener::Listener;
pub use message::{Message, MessageContext};
pub use preconnection::{new_preconnection, Preconnection};
pub use preconnection::Preconnection;
pub use types::*;

#[cfg(test)]
Expand Down
16 changes: 0 additions & 16 deletions src/preconnection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,6 @@ use std::sync::Arc;
use std::time::Duration;
use tokio::sync::RwLock;

/// Create a new Preconnection as defined in RFC Section 6
/// This is the primary way to create a Preconnection object
pub fn new_preconnection(
local_endpoints: Vec<LocalEndpoint>,
remote_endpoints: Vec<RemoteEndpoint>,
transport_properties: TransportProperties,
security_parameters: SecurityParameters,
) -> Preconnection {
Preconnection::new(
local_endpoints,
remote_endpoints,
transport_properties,
security_parameters,
)
}

/// A Preconnection represents a potential Connection
/// It is a passive object that maintains the state describing
/// the properties of a Connection that might exist in the future
Expand Down
8 changes: 4 additions & 4 deletions src/tests/background_reading_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async fn test_background_reading_receives_messages() {
});

// Create connection
let preconn = new_preconnection(
let preconn = Preconnection::new(
vec![],
vec![RemoteEndpoint::builder().socket_address(addr).build()],
TransportProperties::default(),
Expand Down Expand Up @@ -103,7 +103,7 @@ async fn test_background_reading_with_framing() {
});

// Create connection with framing
let preconn = new_preconnection(
let preconn = Preconnection::new(
vec![],
vec![RemoteEndpoint::builder().socket_address(addr).build()],
TransportProperties::default(),
Expand Down Expand Up @@ -164,7 +164,7 @@ async fn test_background_reading_handles_connection_close() {
});

// Create connection
let preconn = new_preconnection(
let preconn = Preconnection::new(
vec![],
vec![RemoteEndpoint::builder().socket_address(addr).build()],
TransportProperties::default(),
Expand Down Expand Up @@ -235,7 +235,7 @@ async fn test_background_reading_concurrent_with_receive() {
});

// Create connection
let preconn = new_preconnection(
let preconn = Preconnection::new(
vec![],
vec![RemoteEndpoint::builder().socket_address(addr).build()],
TransportProperties::default(),
Expand Down
16 changes: 8 additions & 8 deletions src/tests/connection_group_tests.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Unit tests for Connection Groups functionality

use crate::{
preconnection::new_preconnection, ConnectionGroup, ConnectionState, LocalEndpoint, Preference,
RemoteEndpoint, SecurityParameters, TransportProperties,
ConnectionGroup, ConnectionState, LocalEndpoint, Preconnection, Preference, RemoteEndpoint,
SecurityParameters, TransportProperties,
};
use std::time::Duration;
use tokio::net::TcpListener;
Expand All @@ -18,7 +18,7 @@ async fn test_connection_clone_basic() {
.socket_address(server_addr)
.build();

let preconn = new_preconnection(
let preconn = Preconnection::new(
vec![],
vec![remote],
TransportProperties::default(),
Expand Down Expand Up @@ -87,7 +87,7 @@ async fn test_connection_clone_basic() {

#[tokio::test]
async fn test_connection_clone_only_established() {
let preconn = new_preconnection(
let preconn = Preconnection::new(
vec![],
vec![RemoteEndpoint::builder()
.ip_address("127.0.0.1".parse().unwrap())
Expand Down Expand Up @@ -132,7 +132,7 @@ async fn test_connection_group_shared_properties() {
.socket_address(server_addr)
.build();

let preconn = new_preconnection(vec![], vec![remote], props, SecurityParameters::default());
let preconn = Preconnection::new(vec![], vec![remote], props, SecurityParameters::default());

// Create initial connection
let conn1 = preconn.initiate().await.unwrap();
Expand Down Expand Up @@ -180,7 +180,7 @@ async fn test_connection_group_multiple_clones() {
.socket_address(server_addr)
.build();

let preconn = new_preconnection(
let preconn = Preconnection::new(
vec![],
vec![remote],
TransportProperties::default(),
Expand Down Expand Up @@ -250,7 +250,7 @@ async fn test_connection_group_close() {
.socket_address(server_addr)
.build();

let preconn = new_preconnection(
let preconn = Preconnection::new(
vec![],
vec![remote],
TransportProperties::default(),
Expand Down Expand Up @@ -284,7 +284,7 @@ async fn test_connection_group_close() {
#[tokio::test]
async fn test_connection_without_group() {
// Create a connection that won't be cloned
let preconn = new_preconnection(
let preconn = Preconnection::new(
vec![],
vec![RemoteEndpoint::builder()
.ip_address("127.0.0.1".parse().unwrap())
Expand Down
14 changes: 7 additions & 7 deletions src/tests/connection_properties_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::time::Duration;
#[tokio::test]
async fn test_set_and_get_properties() {
// Create a connection for testing
let preconn = new_preconnection(
let preconn = Preconnection::new(
vec![],
vec![RemoteEndpoint::builder()
.hostname("example.com")
Expand Down Expand Up @@ -42,7 +42,7 @@ async fn test_set_and_get_properties() {

#[tokio::test]
async fn test_connection_properties_defaults() {
let preconn = new_preconnection(
let preconn = Preconnection::new(
vec![],
vec![RemoteEndpoint::builder()
.hostname("example.com")
Expand Down Expand Up @@ -84,7 +84,7 @@ async fn test_connection_properties_defaults() {

#[tokio::test]
async fn test_readonly_properties() {
let preconn = new_preconnection(
let preconn = Preconnection::new(
vec![],
vec![RemoteEndpoint::builder()
.hostname("example.com")
Expand Down Expand Up @@ -126,7 +126,7 @@ async fn test_readonly_properties() {

#[tokio::test]
async fn test_readonly_property_rejection() {
let preconn = new_preconnection(
let preconn = Preconnection::new(
vec![],
vec![RemoteEndpoint::builder()
.hostname("example.com")
Expand Down Expand Up @@ -165,7 +165,7 @@ async fn test_readonly_property_rejection() {

#[tokio::test]
async fn test_timeout_properties() {
let preconn = new_preconnection(
let preconn = Preconnection::new(
vec![],
vec![RemoteEndpoint::builder()
.hostname("example.com")
Expand Down Expand Up @@ -205,7 +205,7 @@ async fn test_timeout_properties() {

#[tokio::test]
async fn test_capacity_profile() {
let preconn = new_preconnection(
let preconn = Preconnection::new(
vec![],
vec![RemoteEndpoint::builder()
.hostname("example.com")
Expand Down Expand Up @@ -243,7 +243,7 @@ async fn test_capacity_profile() {

#[tokio::test]
async fn test_rate_limits() {
let preconn = new_preconnection(
let preconn = Preconnection::new(
vec![],
vec![RemoteEndpoint::builder()
.hostname("example.com")
Expand Down
4 changes: 2 additions & 2 deletions src/tests/connection_termination_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async fn create_test_connection() -> Connection {
});

// Create connection
let preconn = new_preconnection(
let preconn = Preconnection::new(
vec![],
vec![RemoteEndpoint::builder().socket_address(addr).build()],
TransportProperties::default(),
Expand Down Expand Up @@ -244,7 +244,7 @@ async fn test_remote_close_detection() {
});

// Create connection
let preconn = new_preconnection(
let preconn = Preconnection::new(
vec![],
vec![RemoteEndpoint::builder().socket_address(addr).build()],
TransportProperties::default(),
Expand Down
10 changes: 5 additions & 5 deletions src/tests/connection_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async fn test_connection_establishment() {
.port(server_addr.port())
.build();

let preconn = new_preconnection(
let preconn = Preconnection::new(
vec![],
vec![remote],
TransportProperties::default(),
Expand Down Expand Up @@ -84,7 +84,7 @@ async fn test_connection_send_receive() {
.port(server_addr.port())
.build();

let preconn = new_preconnection(
let preconn = Preconnection::new(
vec![],
vec![remote],
TransportProperties::default(),
Expand Down Expand Up @@ -123,7 +123,7 @@ async fn test_connection_events() {
.port(server_addr.port())
.build();

let preconn = new_preconnection(
let preconn = Preconnection::new(
vec![],
vec![remote],
TransportProperties::default(),
Expand Down Expand Up @@ -172,7 +172,7 @@ async fn test_connection_timeout() {
.port(12345)
.build();

let preconn = new_preconnection(
let preconn = Preconnection::new(
vec![],
vec![remote],
TransportProperties::default(),
Expand Down Expand Up @@ -225,7 +225,7 @@ async fn test_queued_messages() {
.port(server_addr.port())
.build();

let preconn = new_preconnection(
let preconn = Preconnection::new(
vec![],
vec![remote],
TransportProperties::default(),
Expand Down
12 changes: 6 additions & 6 deletions src/tests/endpoint_management_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::*;

#[tokio::test]
async fn test_add_remote_endpoint_to_establishing_connection() {
let preconn = new_preconnection(
let preconn = Preconnection::new(
vec![],
vec![RemoteEndpoint::builder()
.hostname("example.com")
Expand Down Expand Up @@ -44,7 +44,7 @@ async fn test_add_duplicate_remote_endpoint() {
.port(443)
.build();

let preconn = new_preconnection(
let preconn = Preconnection::new(
vec![],
vec![endpoint.clone()],
TransportProperties::default(),
Expand All @@ -67,7 +67,7 @@ async fn test_add_duplicate_remote_endpoint() {

#[tokio::test]
async fn test_add_remote_to_closed_connection() {
let preconn = new_preconnection(
let preconn = Preconnection::new(
vec![],
vec![RemoteEndpoint::builder()
.hostname("example.com")
Expand Down Expand Up @@ -105,7 +105,7 @@ async fn test_add_remote_to_closed_connection() {

#[tokio::test]
async fn test_add_local_endpoint_to_establishing_connection() {
let preconn = new_preconnection(
let preconn = Preconnection::new(
vec![],
vec![RemoteEndpoint::builder()
.hostname("example.com")
Expand Down Expand Up @@ -143,7 +143,7 @@ async fn test_add_duplicate_local_endpoint() {
identifiers: vec![EndpointIdentifier::Interface("eth0".to_string())],
};

let preconn = new_preconnection(
let preconn = Preconnection::new(
vec![endpoint.clone()],
vec![RemoteEndpoint::builder()
.hostname("example.com")
Expand All @@ -169,7 +169,7 @@ async fn test_add_duplicate_local_endpoint() {

#[tokio::test]
async fn test_add_local_to_closed_connection() {
let preconn = new_preconnection(
let preconn = Preconnection::new(
vec![],
vec![RemoteEndpoint::builder()
.hostname("example.com")
Expand Down
Loading
Loading