Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for bolt 5.3 #7

Merged
merged 1 commit into from
Jan 21, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Reduce the number of lifetime generic parameters in `TransactionQueryBuilder` and `TransactionRecordStream`.
- Fix `Transaction::rolblack()` failing if a result stream failed before.
- Introduce `neo4j::driver::Conifg::with_keep_alive()` and `without_keep_alive()`.
- Add support for Bolt 5.3 (bolt agent).

## 0.0.2
- Update dependencies.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ A bump in MSRV is considered a minor breaking change.
* [x] 5.0 (utc fix)
* [x] 5.1 (re-auth)
* [x] 5.2 (notification filtering)
* [ ] 5.3 (bolt agent)
* [x] 5.3 (bolt agent)
* [ ] 5.4 (telemetry)
* [x] Types
* [x] `Null`
Expand Down
2 changes: 1 addition & 1 deletion neo4j/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "neo4j"
version = "0.0.2"
edition = "2021"
rust-version = "1.65"
rust-version = "1.70"
readme = "../README.md"
description = "Bolt driver for Neo4j."
license = "Apache-2.0"
Expand Down
47 changes: 42 additions & 5 deletions neo4j/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright Rouven Bauer
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use std::env;
use std::process::Command;

Expand Down Expand Up @@ -29,14 +43,37 @@ fn get_rustc_version() -> String {
fn main() {
let rustc_version = get_rustc_version();

let user_agent = format!(
"neo4j-rust-robsdedude/{} Rust/{} {}",
env::var("CARGO_PKG_VERSION").unwrap(),
rustc_version,
env::var("TARGET").unwrap(),
let product = format!(
"neo4j-rust-robsdedude/{}",
env::var("CARGO_PKG_VERSION").unwrap()
);
println!("Setting bolt agent product to: {}", product);

let platform = env::var("TARGET").unwrap();
println!("Setting bolt agent platform to: {}", platform);

let language = format!("Rust/{}", rustc_version);
println!("Setting bolt agent language to: {}", language);

let language_details = format!(
"profile: {}; host: {}",
env::var("PROFILE").unwrap(),
env::var("HOST").unwrap()
);
println!(
"Setting bolt agent language details to: {}",
language_details
);

let user_agent = format!("{} {} {}", product, language, platform);
println!("Setting default user agent to: {}", user_agent);

println!("cargo:rustc-env=NEO4J_DEFAULT_USER_AGENT={}", user_agent);
println!("cargo:rustc-env=NEO4J_BOLT_AGENT_PRODUCT={}", product);
println!("cargo:rustc-env=NEO4J_BOLT_AGENT_PLATFORM={}", platform);
println!("cargo:rustc-env=NEO4J_BOLT_AGENT_LANGUAGE={}", language);
println!(
"cargo:rustc-env=NEO4J_BOLT_AGENT_LANGUAGE_DETAILS={}",
language_details
);
}
7 changes: 6 additions & 1 deletion neo4j/src/driver/io/bolt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ mod bolt4x4;
mod bolt5x0;
mod bolt5x1;
mod bolt5x2;
mod bolt5x3;
mod bolt_state;
mod chunk;
mod message;
Expand Down Expand Up @@ -58,6 +59,7 @@ use bolt4x4::{Bolt4x4, Bolt4x4StructTranslator};
use bolt5x0::{Bolt5x0, Bolt5x0StructTranslator};
use bolt5x1::{Bolt5x1, Bolt5x1StructTranslator};
use bolt5x2::{Bolt5x2, Bolt5x2StructTranslator};
use bolt5x3::{Bolt5x3, Bolt5x3StructTranslator};
use bolt_state::{BoltState, BoltStateTracker};
use chunk::{Chunker, Dechunker};
use message::BoltMessage;
Expand Down Expand Up @@ -172,6 +174,7 @@ impl<RW: Read + Write> Bolt<RW> {
data: BoltData::new(version, stream, socket, local_port, address),
// [bolt-version-bump] search tag when changing bolt version support
protocol: match version {
(5, 3) => Bolt5x3::<Bolt5x3StructTranslator>::default().into(),
(5, 2) => Bolt5x2::<Bolt5x2StructTranslator>::default().into(),
(5, 1) => Bolt5x1::<Bolt5x1StructTranslator>::default().into(),
(5, 0) => Bolt5x0::<Bolt5x0StructTranslator>::default().into(),
Expand Down Expand Up @@ -472,6 +475,7 @@ enum BoltProtocolVersion {
V5x0(Bolt5x0<Bolt5x0StructTranslator>),
V5x1(Bolt5x1<Bolt5x1StructTranslator>),
V5x2(Bolt5x2<Bolt5x2StructTranslator>),
V5x3(Bolt5x3<Bolt5x3StructTranslator>),
}

#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]
Expand Down Expand Up @@ -807,7 +811,7 @@ fn assert_response_field_count<T>(name: &str, fields: &[T], expected_count: usiz
const BOLT_MAGIC_PREAMBLE: [u8; 4] = [0x60, 0x60, 0xB0, 0x17];
// [bolt-version-bump] search tag when changing bolt version support
const BOLT_VERSION_OFFER: [u8; 16] = [
0, 2, 2, 5, // BOLT 5.2 - 5.0
0, 3, 3, 5, // BOLT 5.3 - 5.0
0, 0, 4, 4, // BOLT 4.4
0, 0, 0, 0, // -
0, 0, 0, 0, // -
Expand Down Expand Up @@ -885,6 +889,7 @@ pub(crate) fn open(
[0, 0, 0, 0] => Err(Neo4jError::InvalidConfig {
message: String::from("server version not supported"),
}),
[0, 0, 3, 5] => Ok((5, 3)),
[0, 0, 2, 5] => Ok((5, 2)),
[0, 0, 1, 5] => Ok((5, 1)),
[0, 0, 0, 5] => Ok((5, 0)),
Expand Down
4 changes: 2 additions & 2 deletions neo4j/src/driver/io/bolt/bolt5x2/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ impl<T: BoltStructTranslator> Bolt5x2<T> {
}
}

pub(in super::super) fn write_notification_filter<W: Write>(
pub(in super::super) fn write_notification_filter(
mut log_buf: Option<&mut String>,
serializer: &mut PackStreamSerializerImpl<W>,
serializer: &mut PackStreamSerializerImpl<impl Write>,
dbg_serializer: &mut PackStreamSerializerDebugImpl,
notification_filter: Option<&NotificationFilter>,
) -> Result<()> {
Expand Down
19 changes: 19 additions & 0 deletions neo4j/src/driver/io/bolt/bolt5x3.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright Rouven Bauer
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

mod protocol;
mod translator;

pub(crate) use protocol::Bolt5x3;
pub(crate) use translator::Bolt5x3StructTranslator;
Loading