Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
daniel.eades
arti
Commits
7e50c4ad
Commit
7e50c4ad
authored
Nov 20, 2020
by
Nick Mathewson
🎨
Browse files
Move storage and config logic from netdir to dirmgr.
parent
21ebb5ca
Changes
12
Hide whitespace changes
Inline
Side-by-side
client-demo/src/main.rs
View file @
7e50c4ad
...
@@ -112,7 +112,7 @@ fn get_netdir(args: &Args) -> Result<tor_netdir::NetDir> {
...
@@ -112,7 +112,7 @@ fn get_netdir(args: &Args) -> Result<tor_netdir::NetDir> {
eprintln!
(
"Can't specify both --tor-dir and --chutney-dir"
);
eprintln!
(
"Can't specify both --tor-dir and --chutney-dir"
);
return
Err
(
anyhow!
(
"Conflicting --tor-dir and --chutney-dir"
));
return
Err
(
anyhow!
(
"Conflicting --tor-dir and --chutney-dir"
));
}
}
let
mut
cfg
=
tor_
netdi
r
::
NetDirConfigBuilder
::
new
();
let
mut
cfg
=
tor_
dirmg
r
::
NetDirConfigBuilder
::
new
();
if
let
Some
(
ref
d
)
=
args
.tor_dir
{
if
let
Some
(
ref
d
)
=
args
.tor_dir
{
cfg
.add_default_authorities
();
cfg
.add_default_authorities
();
...
@@ -266,10 +266,10 @@ fn main() -> Result<()> {
...
@@ -266,10 +266,10 @@ fn main() -> Result<()> {
// TODO: This is just a kludge for testing.
// TODO: This is just a kludge for testing.
if
args
.dirclient
{
if
args
.dirclient
{
let
fb
=
tor_netdir
::
fallback
::
FallbackSet
::
new
();
let
fb
=
tor_netdir
::
fallback
::
FallbackSet
::
new
();
let
store
=
tor_
netdi
r
::
storage
::
sqlite
::
SqliteStore
::
from_path
(
"/home/nickm/.arti"
)
?
;
let
store
=
tor_
dirmg
r
::
storage
::
sqlite
::
SqliteStore
::
from_path
(
"/home/nickm/.arti"
)
?
;
let
store
=
tor_dirmgr
::
DirStoreHandle
::
new
(
store
);
let
store
=
tor_dirmgr
::
DirStoreHandle
::
new
(
store
);
let
circmgr
=
Arc
::
new
(
circmgr
);
let
circmgr
=
Arc
::
new
(
circmgr
);
let
mut
cfg
=
tor_
netdi
r
::
NetDirConfigBuilder
::
new
();
let
mut
cfg
=
tor_
dirmg
r
::
NetDirConfigBuilder
::
new
();
cfg
.add_default_authorities
();
cfg
.add_default_authorities
();
let
cfg
=
cfg
.finalize
();
let
cfg
=
cfg
.finalize
();
let
authorities
=
cfg
.into_authorities
();
let
authorities
=
cfg
.into_authorities
();
...
...
tor-dirmgr/Cargo.toml
View file @
7e50c4ad
...
@@ -17,13 +17,21 @@ tor-llcrypto = { path="../tor-llcrypto", version= "*" }
...
@@ -17,13 +17,21 @@ tor-llcrypto = { path="../tor-llcrypto", version= "*" }
tor-rtcompat
=
{
path
=
"../tor-rtcompat"
,
version
=
"*"
}
tor-rtcompat
=
{
path
=
"../tor-rtcompat"
,
version
=
"*"
}
anyhow
=
"1.0.34"
anyhow
=
"1.0.34"
async-trait
=
"0.1.41"
async-rwlock
=
"1.3.0"
async-rwlock
=
"1.3.0"
async-trait
=
"0.1.41"
base64
=
"0.13.0"
chrono
=
"0.4.19"
digest
=
"0.9.0"
event-listener
=
"2.5.1"
event-listener
=
"2.5.1"
futures
=
"0.3.8"
futures
=
"0.3.8"
rand
=
"0.
7.3
"
hex
=
"0.
4.2
"
log
=
"0.4.11"
log
=
"0.4.11"
memmap
=
"0.7.0"
rand
=
"0.7.3"
rusqlite
=
{
version
=
"0.24.1"
,
features
=
["chrono"]
}
thiserror
=
"1.0.22"
thiserror
=
"1.0.22"
[dev-dependencies]
[dev-dependencies]
futures-await-test
=
"0.3.0"
futures-await-test
=
"0.3.0"
hex-literal
=
"0.3.1"
tempdir
=
"0.3.7"
tor-
netdi
r/src/authority.rs
→
tor-
dirmg
r/src/authority.rs
View file @
7e50c4ad
File moved
tor-
netdi
r/src/config.rs
→
tor-
dirmg
r/src/config.rs
View file @
7e50c4ad
...
@@ -3,11 +3,11 @@
...
@@ -3,11 +3,11 @@
//! Directory configuration tells us where to load and store directory
//! Directory configuration tells us where to load and store directory
//! information ,where to fetch it from, and how to validate it.
//! information ,where to fetch it from, and how to validate it.
use
crate
::
fallback
::{
FallbackDir
,
FallbackSet
};
use
crate
::
storage
::
legacy
::
LegacyStore
;
use
crate
::
storage
::
legacy
::
LegacyStore
;
use
crate
::
Authority
;
use
crate
::
Authority
;
use
crate
::
PartialNetDir
;
use
crate
::
PartialNetDir
;
use
crate
::{
Error
,
Result
};
use
crate
::{
Error
,
Result
};
use
tor_netdir
::
fallback
::{
FallbackDir
,
FallbackSet
};
use
tor_llcrypto
::
pk
::
ed25519
::
Ed25519Identity
;
use
tor_llcrypto
::
pk
::
ed25519
::
Ed25519Identity
;
use
tor_llcrypto
::
pk
::
rsa
::
RSAIdentity
;
use
tor_llcrypto
::
pk
::
rsa
::
RSAIdentity
;
...
...
tor-
netdi
r/src/docmeta.rs
→
tor-
dirmg
r/src/docmeta.rs
View file @
7e50c4ad
File moved
tor-dirmgr/src/err.rs
0 → 100644
View file @
7e50c4ad
//! Declare an error type for the dirmgr crate.
use
thiserror
::
Error
;
/// An error originated by the directory manager code
#[derive(Error,
Debug)]
pub
enum
Error
{
/// We received a document we didn't want at all.
#[error(
"unwanted object: {0}"
)]
Unwanted
(
&
'static
str
),
/// A bad argument was provided to some configuration function.
#[error(
"bad argument: {0}"
)]
BadArgument
(
&
'static
str
),
/// We couldn't read something from disk that we should have been
/// able to read.
#[error(
"corrupt cache: {0}"
)]
CacheCorruption
(
&
'static
str
),
/// rusqlite gave us an error.
#[error(
"sqlite error: {0}"
)]
SqliteError
(
#[from]
rusqlite
::
Error
),
/// A schema version that says we can't read it.
#[error(
"unrecognized data storage schema"
)]
UnrecognizedSchema
,
}
tor-dirmgr/src/lib.rs
View file @
7e50c4ad
#![allow(unused_variables)]
#![allow(unused_variables)]
#![allow(unused)]
#![allow(unused)]
pub
mod
authority
;
// TODO: make this private.
mod
config
;
mod
docmeta
;
mod
err
;
pub
mod
storage
;
use
crate
::
docmeta
::
ConsensusMeta
;
use
crate
::
storage
::
sqlite
::
SqliteStore
;
use
tor_checkable
::{
ExternallySigned
,
SelfSigned
,
Timebound
};
use
tor_checkable
::{
ExternallySigned
,
SelfSigned
,
Timebound
};
use
tor_circmgr
::{
CircMgr
,
DirInfo
};
use
tor_circmgr
::{
CircMgr
,
DirInfo
};
use
tor_netdir
::
docmeta
::
ConsensusMeta
;
use
tor_netdir
::{
MDReceiver
,
NetDir
,
PartialNetDir
};
use
tor_netdir
::
storage
::
sqlite
::
SqliteStore
;
use
tor_netdir
::{
Authority
,
MDReceiver
,
NetDir
,
PartialNetDir
};
use
tor_netdoc
::
doc
::
authcert
::{
AuthCert
,
AuthCertKeyIds
};
use
tor_netdoc
::
doc
::
authcert
::{
AuthCert
,
AuthCertKeyIds
};
use
tor_netdoc
::
doc
::
microdesc
::{
MDDigest
,
Microdesc
,
MicrodescReader
};
use
tor_netdoc
::
doc
::
microdesc
::{
MDDigest
,
Microdesc
,
MicrodescReader
};
use
tor_netdoc
::
doc
::
netstatus
::{
MDConsensus
,
UnvalidatedMDConsensus
};
use
tor_netdoc
::
doc
::
netstatus
::{
MDConsensus
,
UnvalidatedMDConsensus
};
use
tor_netdoc
::
AllowAnnotations
;
use
tor_netdoc
::
AllowAnnotations
;
use
anyhow
::{
anyhow
,
Error
,
Result
};
use
anyhow
::{
anyhow
,
Result
};
use
async_rwlock
::
RwLock
;
use
async_rwlock
::
RwLock
;
use
std
::
collections
::
HashSet
;
use
std
::
collections
::
HashSet
;
...
@@ -21,6 +28,10 @@ use std::path::Path;
...
@@ -21,6 +28,10 @@ use std::path::Path;
use
std
::
sync
::
Arc
;
use
std
::
sync
::
Arc
;
use
std
::
time
::
SystemTime
;
use
std
::
time
::
SystemTime
;
pub
use
authority
::
Authority
;
pub
use
config
::{
NetDirConfig
,
NetDirConfigBuilder
};
pub
use
err
::
Error
;
/*
/*
// XXXX shouldn't be pub.
// XXXX shouldn't be pub.
#[derive(Debug)]
#[derive(Debug)]
...
...
tor-
netdi
r/src/storage.rs
→
tor-
dirmg
r/src/storage.rs
View file @
7e50c4ad
...
@@ -24,7 +24,7 @@ impl InputString {
...
@@ -24,7 +24,7 @@ impl InputString {
InputString
::
UncheckedBytes
(
v
)
=>
std
::
str
::
from_utf8
(
&
v
[
..
]),
InputString
::
UncheckedBytes
(
v
)
=>
std
::
str
::
from_utf8
(
&
v
[
..
]),
InputString
::
MappedBytes
(
m
)
=>
std
::
str
::
from_utf8
(
&
m
[
..
]),
InputString
::
MappedBytes
(
m
)
=>
std
::
str
::
from_utf8
(
&
m
[
..
]),
}
}
.map_err
(|
_
|
Error
::
CacheCorruption
(
"Invalid UTF-8"
))
.map_err
(|
_
|
Error
::
CacheCorruption
(
"Invalid UTF-8"
)
.into
()
)
}
}
pub
fn
load
<
P
:
AsRef
<
Path
>>
(
path
:
P
)
->
Result
<
Self
>
{
pub
fn
load
<
P
:
AsRef
<
Path
>>
(
path
:
P
)
->
Result
<
Self
>
{
...
...
tor-
netdi
r/src/storage/legacy.rs
→
tor-
dirmg
r/src/storage/legacy.rs
View file @
7e50c4ad
...
@@ -61,12 +61,12 @@ impl LegacyStore {
...
@@ -61,12 +61,12 @@ impl LegacyStore {
let
text
=
input
.as_str
()
?
;
let
text
=
input
.as_str
()
?
;
for
cert
in
AuthCert
::
parse_multiple
(
text
)
{
for
cert
in
AuthCert
::
parse_multiple
(
text
)
{
let
r
=
(||
{
let
r
:
Result
<
_
>
=
(||
{
let
cert
=
cert
?
.check_signature
()
?
.check_valid_now
()
?
;
let
cert
=
cert
?
.check_signature
()
?
.check_valid_now
()
?
;
let
found
=
authorities
.iter
()
.any
(|
a
|
a
.matches_cert
(
&
cert
));
let
found
=
authorities
.iter
()
.any
(|
a
|
a
.matches_cert
(
&
cert
));
if
!
found
{
if
!
found
{
return
Err
(
Error
::
Unwanted
(
"no such authority"
));
return
Err
(
Error
::
Unwanted
(
"no such authority"
)
.into
()
);
}
}
Ok
(
cert
)
Ok
(
cert
)
})();
})();
...
...
tor-
netdi
r/src/storage/sqlite.rs
→
tor-
dirmg
r/src/storage/sqlite.rs
View file @
7e50c4ad
...
@@ -80,7 +80,7 @@ impl SqliteStore {
...
@@ -80,7 +80,7 @@ impl SqliteStore {
return Ok(())
return Ok(())
} else */
} else */
if
readable_by
>
SCHEMA_VERSION
{
if
readable_by
>
SCHEMA_VERSION
{
return
Err
(
Error
::
UnrecognizedSchema
);
return
Err
(
Error
::
UnrecognizedSchema
.into
()
);
}
}
// rolls back the transaction, but nothing was done.
// rolls back the transaction, but nothing was done.
...
@@ -121,7 +121,7 @@ impl SqliteStore {
...
@@ -121,7 +121,7 @@ impl SqliteStore {
.components
()
.components
()
.all
(|
c
|
matches!
(
c
,
path
::
Component
::
Normal
(
_
)))
.all
(|
c
|
matches!
(
c
,
path
::
Component
::
Normal
(
_
)))
{
{
return
Err
(
Error
::
CacheCorruption
(
"Invalid path in database"
));
return
Err
(
Error
::
CacheCorruption
(
"Invalid path in database"
)
.into
()
);
}
}
let
mut
result
=
self
.path
.clone
();
let
mut
result
=
self
.path
.clone
();
...
...
tor-netdir/Cargo.toml
View file @
7e50c4ad
...
@@ -14,12 +14,9 @@ tor-llcrypto = { path="../tor-llcrypto", version= "*" }
...
@@ -14,12 +14,9 @@ tor-llcrypto = { path="../tor-llcrypto", version= "*" }
tor-protover
=
{
path
=
"../tor-protover"
,
version
=
"*"
}
tor-protover
=
{
path
=
"../tor-protover"
,
version
=
"*"
}
base64
=
"0.13.0"
base64
=
"0.13.0"
chrono
=
"0.4.19"
digest
=
"0.9.0"
digest
=
"0.9.0"
hex
=
"0.4.2"
hex
=
"0.4.2"
lazy_static
=
"1.4.0"
lazy_static
=
"1.4.0"
log
=
"0.4.11"
memmap
=
"0.7.0"
rand
=
"0.7.3"
rand
=
"0.7.3"
rusqlite
=
{
version
=
"0.24.1"
,
features
=
["chrono"]
}
rusqlite
=
{
version
=
"0.24.1"
,
features
=
["chrono"]
}
signature
=
"1.2.2"
signature
=
"1.2.2"
...
@@ -28,4 +25,3 @@ thiserror = "1.0.22"
...
@@ -28,4 +25,3 @@ thiserror = "1.0.22"
[dev-dependencies]
[dev-dependencies]
hex-literal
=
"0.3.1"
hex-literal
=
"0.3.1"
simple-logging
=
"2.0.2"
simple-logging
=
"2.0.2"
tempdir
=
"0.3.7"
\ No newline at end of file
tor-netdir/src/lib.rs
View file @
7e50c4ad
...
@@ -20,13 +20,9 @@
...
@@ -20,13 +20,9 @@
#![deny(missing_docs)]
#![deny(missing_docs)]
#![deny(clippy::missing_docs_in_private_items)]
#![deny(clippy::missing_docs_in_private_items)]
mod
authority
;
mod
config
;
pub
mod
docmeta
;
mod
err
;
mod
err
;
pub
mod
fallback
;
pub
mod
fallback
;
mod
pick
;
mod
pick
;
pub
mod
storage
;
use
ll
::
pk
::
rsa
::
RSAIdentity
;
use
ll
::
pk
::
rsa
::
RSAIdentity
;
use
tor_llcrypto
as
ll
;
use
tor_llcrypto
as
ll
;
...
@@ -39,9 +35,6 @@ pub use err::Error;
...
@@ -39,9 +35,6 @@ pub use err::Error;
/// A Result using the Error type from the tor-netdir crate
/// A Result using the Error type from the tor-netdir crate
pub
type
Result
<
T
>
=
std
::
result
::
Result
<
T
,
Error
>
;
pub
type
Result
<
T
>
=
std
::
result
::
Result
<
T
,
Error
>
;
pub
use
authority
::
Authority
;
pub
use
config
::{
NetDirConfig
,
NetDirConfigBuilder
};
/// Internal: how should we find the base weight of each relay? This
/// Internal: how should we find the base weight of each relay? This
/// value is global over a whole directory, and depends on the bandwidth
/// value is global over a whole directory, and depends on the bandwidth
/// weights in the consensus.
/// weights in the consensus.
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment