Skip to content

Commit d52f7eb

Browse files
authored
Merge pull request #190 from AdExNetwork/bb8
Updates dependencies and adds bb8
2 parents 432620a + fa77028 commit d52f7eb

File tree

9 files changed

+841
-547
lines changed

9 files changed

+841
-547
lines changed

Cargo.lock

Lines changed: 794 additions & 526 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

adapter/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ web3 = { git = "https://github.com/tomusdrw/rust-web3" }
2020
eth_checksum = "0.1.1"
2121
ethabi = "8.0.1"
2222
tiny-keccak = "1.5"
23-
ethkey = { git = "https://github.com/paritytech/parity.git" }
24-
ethstore = { git = "https://github.com/paritytech/parity.git" }
23+
parity-crypto = { version = "0.4.2", features = ["publickey"], git = "https://github.com/paritytech/parity-common" }
24+
ethstore = { version = "0.2.1", git = "https://github.com/paritytech/parity-ethereum"}
25+
ethkey = { version = "0.4.0", git = "https://github.com/paritytech/parity-ethereum"}
2526
sha2 = "0.8.0"
2627
base64 = "0.10.1"
2728
lazy_static = "1.4.0"

adapter/src/ethereum.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
use crate::EthereumChannel;
22
use chrono::Utc;
3-
use ethkey::{public_to_address, recover, verify_address, Address, Message, Password, Signature};
3+
use ethkey::Password;
44
use ethstore::SafeAccount;
55
use lazy_static::lazy_static;
6+
use parity_crypto::publickey::{
7+
public_to_address, recover, verify_address, Address, Message, Signature,
8+
};
69
use primitives::{
710
adapter::{Adapter, AdapterError, AdapterResult, KeystoreOptions, Session},
811
channel_validator::ChannelValidator,

sentry/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ tokio = "0.2.0-alpha.6"
1919
hyper = {version = "=0.13.0-alpha.4", features = ["unstable-stream"]}
2020
regex = "1"
2121
# Database
22-
redis = {version = "0.13.1-alpha.0", features = ["executor"]}
22+
redis = {version = "0.13.1-alpha.0", features = ["tokio-executor"]}
23+
bb8 = {git = "https://github.com/djc/bb8", branch = "async-await"}
24+
bb8-postgres = {git = "https://github.com/djc/bb8", branch = "async-await"}
2325
# Logger
2426
slog = { version = "^2.2.3" , features = ["max_level_trace"] }
2527
# Serde

sentry/src/access.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use chrono::Utc;
22
use futures::future::try_join_all;
3-
use redis::aio::SharedConnection;
3+
use redis::aio::MultiplexedConnection;
44

55
use primitives::event_submission::{RateLimit, Rule};
66
use primitives::sentry::Event;
@@ -18,7 +18,7 @@ pub enum Error {
1818

1919
// @TODO: Make pub(crate)
2020
pub async fn check_access(
21-
redis: &SharedConnection,
21+
redis: &MultiplexedConnection,
2222
session: &Session,
2323
rate_limit: &RateLimit,
2424
channel: &Channel,
@@ -91,7 +91,7 @@ pub async fn check_access(
9191
}
9292

9393
async fn apply_rule(
94-
redis: SharedConnection,
94+
redis: MultiplexedConnection,
9595
rule: &Rule,
9696
events: &[Event],
9797
channel: &Channel,
@@ -164,7 +164,7 @@ mod test {
164164

165165
use super::*;
166166

167-
async fn setup() -> (Config, SharedConnection) {
167+
async fn setup() -> (Config, MultiplexedConnection) {
168168
let mut redis = redis_connection().await.expect("Couldn't connect to Redis");
169169
let config = configuration("development", None).expect("Failed to get dev configuration");
170170

sentry/src/db.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
1-
use redis::aio::SharedConnection;
1+
use redis::aio::MultiplexedConnection;
22
use redis::RedisError;
33

4+
use bb8::Pool;
5+
use bb8_postgres::{
6+
tokio_postgres::{Error as PostgresError, NoTls},
7+
PostgresConnectionManager,
8+
};
49
use lazy_static::lazy_static;
510

611
lazy_static! {
712
static ref REDIS_URL: String =
813
std::env::var("REDIS_URL").unwrap_or_else(|_| String::from("redis://127.0.0.1:6379"));
14+
static ref POSTGRES_URL: String = std::env::var("POSTGRES_URL")
15+
.unwrap_or_else(|_| String::from("postgresql://postgres:postgres@localhost:5432"));
916
}
1017

11-
pub async fn redis_connection() -> Result<SharedConnection, RedisError> {
18+
pub async fn redis_connection() -> Result<MultiplexedConnection, RedisError> {
1219
let client = redis::Client::open(REDIS_URL.as_str()).expect("Wrong redis connection string");
13-
client.get_shared_async_connection().await
20+
client.get_multiplexed_tokio_connection().await
21+
}
22+
23+
pub async fn postgres_connection() -> Result<Pool<PostgresConnectionManager<NoTls>>, PostgresError>
24+
{
25+
let pg_mgr = PostgresConnectionManager::new_from_stringlike(POSTGRES_URL.as_str(), NoTls)?;
26+
27+
Pool::builder().build(pg_mgr).await
1428
}

sentry/src/lib.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33

44
use crate::middleware::auth;
55
use crate::middleware::cors::{cors, Cors};
6+
use bb8::Pool;
7+
use bb8_postgres::{tokio_postgres::NoTls, PostgresConnectionManager};
68
use hyper::service::{make_service_fn, service_fn};
79
use hyper::{Body, Error, Method, Request, Response, Server, StatusCode};
810
use primitives::adapter::Adapter;
911
use primitives::Config;
10-
use redis::aio::SharedConnection;
12+
use redis::aio::MultiplexedConnection;
1113
use slog::{error, info, Logger};
1214

1315
pub mod middleware {
@@ -40,7 +42,8 @@ pub mod event_reducer;
4042
pub struct Application<A: Adapter> {
4143
adapter: A,
4244
logger: Logger,
43-
redis: SharedConnection,
45+
redis: MultiplexedConnection,
46+
_postgres: Pool<PostgresConnectionManager<NoTls>>,
4447
_clustered: bool,
4548
port: u16,
4649
config: Config,
@@ -51,7 +54,8 @@ impl<A: Adapter + 'static> Application<A> {
5154
adapter: A,
5255
config: Config,
5356
logger: Logger,
54-
redis: SharedConnection,
57+
redis: MultiplexedConnection,
58+
postgres: Pool<PostgresConnectionManager<NoTls>>,
5559
clustered: bool,
5660
port: u16,
5761
) -> Self {
@@ -60,6 +64,7 @@ impl<A: Adapter + 'static> Application<A> {
6064
config,
6165
logger,
6266
redis,
67+
_postgres: postgres,
6368
_clustered: clustered,
6469
port,
6570
}
@@ -120,7 +125,7 @@ where
120125
async fn handle_routing(
121126
req: Request<Body>,
122127
(adapter, config): (&impl Adapter, &Config),
123-
redis: SharedConnection,
128+
redis: MultiplexedConnection,
124129
logger: &Logger,
125130
) -> Response<Body> {
126131
let headers = match cors(&req) {

sentry/src/main.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use primitives::config::configuration;
99
use primitives::util::logging::{Async, PrefixedCompactFormat, TermDecorator};
1010
use primitives::util::tests::prep_db::{AUTH, IDS};
1111
use primitives::ValidatorId;
12-
use sentry::db::redis_connection;
12+
use sentry::db::{postgres_connection, redis_connection};
1313
use sentry::Application;
1414
use slog::{o, Drain, Logger};
1515
use std::convert::TryFrom;
@@ -98,15 +98,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
9898

9999
let logger = logger();
100100
let redis = redis_connection().await?;
101+
let postgres = postgres_connection().await?;
101102

102103
match adapter {
103104
AdapterTypes::EthereumAdapter(adapter) => {
104-
Application::new(*adapter, config, logger, redis, clustered, port)
105+
Application::new(*adapter, config, logger, redis, postgres, clustered, port)
105106
.run()
106107
.await
107108
}
108109
AdapterTypes::DummyAdapter(adapter) => {
109-
Application::new(*adapter, config, logger, redis, clustered, port)
110+
Application::new(*adapter, config, logger, redis, postgres, clustered, port)
110111
.run()
111112
.await
112113
}

sentry/src/middleware/auth.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::error;
22

33
use hyper::header::AUTHORIZATION;
44
use hyper::{Body, Request};
5-
use redis::aio::SharedConnection;
5+
use redis::aio::MultiplexedConnection;
66

77
use primitives::adapter::{Adapter, Session as AdapterSession};
88

@@ -13,7 +13,7 @@ use crate::Session;
1313
pub(crate) async fn for_request(
1414
mut req: Request<Body>,
1515
adapter: &impl Adapter,
16-
redis: SharedConnection,
16+
redis: MultiplexedConnection,
1717
) -> Result<Request<Body>, Box<dyn error::Error>> {
1818
let authorization = req.headers().get(AUTHORIZATION);
1919

@@ -90,7 +90,7 @@ mod test {
9090

9191
use super::*;
9292

93-
async fn setup() -> (DummyAdapter, SharedConnection) {
93+
async fn setup() -> (DummyAdapter, MultiplexedConnection) {
9494
let adapter_options = DummyAdapterOptions {
9595
dummy_identity: IDS["leader"].clone(),
9696
dummy_auth: IDS.clone(),

0 commit comments

Comments
 (0)