Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
fu050409 committed Mar 25, 2024
2 parents 8b59f26 + 0a6d937 commit bf3b36b
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 7 deletions.
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM ubuntu:22.04
RUN mkdir /root/.cargo
COPY ./ /root/oblivion-rust
COPY ./rsproxy.config /root/.cargo/config
COPY ./ubuntu.list /etc/apt/source.list
RUN apt-get update && apt-get install -y rustc cargo
WORKDIR /root/oblivion-rust
ENTRYPOINT ["cargo", "run", "--release"]
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ You can use the following command to create `Oblivion` documents:
```bash
cargo doc -r
```

## Docker && docker-compose
```bash
docker-compose up -d
```
2 changes: 1 addition & 1 deletion codehere.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
code .
powershell -c "Start-Process -WindowStyle hidden -FilePath "code .""
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '3'
services:
oblivion-rust:
build: .
container_name: oblivion-rust
ports:
- "7076:7076"
10 changes: 10 additions & 0 deletions rsproxy.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[source.crates-io]
replace-with = 'rsproxy-sparse'
[source.rsproxy]
registry = "https://rsproxy.cn/crates.io-index"
[source.rsproxy-sparse]
registry = "sparse+https://rsproxy.cn/index/"
[registries.rsproxy]
index = "https://rsproxy.cn/crates.io-index"
[net]
git-fetch-with-cli = true
6 changes: 4 additions & 2 deletions src/exceptions.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! # Oblivion exception
//! All exceptions to the Oblivion function return `OblivionException`.
#[cfg(feature = "python")]
use pyo3::prelude::*;
use ring::error::Unspecified;
use scrypt::errors::InvalidOutputLen;
use thiserror::Error;
#[cfg(feature = "python")]
use pyo3::prelude::*;

/// ## Oblivion exception iterator
/// Use an iterator as the type of exception returned by a function.
Expand Down Expand Up @@ -55,6 +55,8 @@ pub enum OblivionException {
EncryptError { error: Unspecified },
#[error("Exception while decrypting: {error:?}")]
DecryptError { error: Unspecified },
#[error("Failed to send some data: {message}")]
TCPWriteFailed { message: String },
}

#[cfg(feature = "python")]
Expand Down
15 changes: 11 additions & 4 deletions src/utils/gear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl AbsoluteNonceSequence {
///
/// Used to abstract Oblivion's handling of transmitted data, wrapping all data type conversions.
pub struct Socket {
tcp: TcpStream,
pub tcp: TcpStream,
}

impl Socket {
Expand Down Expand Up @@ -101,9 +101,16 @@ impl Socket {
}

pub async fn send(&mut self, data: &[u8]) -> Result<(), OblivionException> {
match self.tcp.write(data).await {
Ok(_) => Ok(()),
Err(_) => Err(OblivionException::UnexpectedDisconnection),
match self.tcp.write_all(&data).await {
Ok(_) => match self.tcp.flush().await {
Ok(_) => Ok(()),
Err(e) => Err(OblivionException::TCPWriteFailed {
message: e.to_string(),
}),
},
Err(e) => Err(OblivionException::TCPWriteFailed {
message: e.to_string(),
}),
}
}

Expand Down
15 changes: 15 additions & 0 deletions ubuntu.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
deb https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse

# deb https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse

0 comments on commit bf3b36b

Please sign in to comment.