Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Dapp refresh #5752

Merged
merged 40 commits into from
Aug 9, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
2d19a67
RwLock
CraigglesO Jun 1, 2017
11f4fa5
getting there
CraigglesO Jun 2, 2017
1c80221
argh
CraigglesO Jun 2, 2017
9adfdc0
parking_lot
CraigglesO Jun 2, 2017
8428b23
Merge branch 'master' of github.com:paritytech/parity into dapp-refresh
CraigglesO Jun 17, 2017
c0e0022
rpc
CraigglesO Jun 22, 2017
baa2846
Merge branch 'master' of github.com:paritytech/parity into dapp-refresh
CraigglesO Jun 26, 2017
ca573b8
wax on wax off
CraigglesO Jun 27, 2017
83430c0
almost there
CraigglesO Jul 2, 2017
25e5168
remove lock
CraigglesO Jul 2, 2017
98a3eee
write over read
CraigglesO Jul 3, 2017
3815c17
Merge branch 'master' of github.com:paritytech/parity into dapp-refresh
CraigglesO Jul 3, 2017
5004dd3
works
CraigglesO Jul 3, 2017
97ae381
linting
CraigglesO Jul 3, 2017
09e7533
small updates
CraigglesO Jul 4, 2017
95a90ff
dissapearing act
CraigglesO Jul 4, 2017
e7961b5
router update
CraigglesO Jul 4, 2017
f0d162d
complete
CraigglesO Jul 5, 2017
960731c
one m
CraigglesO Jul 5, 2017
5a93a74
grumbles1
CraigglesO Jul 7, 2017
d3fbfb8
grumbles part II
CraigglesO Jul 7, 2017
e5f4a90
parking_lot->util
CraigglesO Jul 7, 2017
bda230b
missed test case
CraigglesO Jul 11, 2017
7c7bd00
fied package-lock.json
CraigglesO Jul 11, 2017
00a84ba
ff
CraigglesO Jul 12, 2017
9433c5c
small fixes
CraigglesO Jul 12, 2017
706db10
404 tests failing
CraigglesO Jul 12, 2017
c4e2c88
cleanup
CraigglesO Jul 12, 2017
04bd4d9
cleanup 2
CraigglesO Jul 12, 2017
0327eec
updates and the likes
CraigglesO Jul 12, 2017
4b45b02
play
CraigglesO Jul 14, 2017
9242dc5
simplify filter
CraigglesO Jul 15, 2017
fea37ce
f-ing bugs
CraigglesO Jul 15, 2017
785bed3
read->write
CraigglesO Jul 15, 2017
faa4cc1
Merge branch 'master' of github.com:paritytech/parity into dapp-refresh
CraigglesO Jul 15, 2017
8c0123c
Merge branch 'master' of github.com:paritytech/parity into dapp-refresh
CraigglesO Jul 18, 2017
dddd303
Address own grumbles.
tomusdrw Jul 31, 2017
64633ec
Fix test.
tomusdrw Jul 31, 2017
004c9d3
Merge pull request #6192 from paritytech/dapps-refresh-fixes
CraigglesO Aug 1, 2017
03a5eb1
Merge branch 'master' into dapp-refresh
tomusdrw Aug 2, 2017
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 Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dapps/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ futures = "0.1"
linked-hash-map = "0.3"
log = "0.3"
parity-dapps-glue = "1.7"
parking_lot = "0.4"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RwLock is re-export in util.

mime = "0.2"
mime_guess = "1.6.1"
rand = "0.3"
Expand Down
3 changes: 2 additions & 1 deletion dapps/src/apps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use std::collections::BTreeMap;
use std::path::PathBuf;
use std::sync::Arc;
use parking_lot::RwLock;

use endpoint::{Endpoints, Endpoint};
use page::PageEndpoint;
Expand Down Expand Up @@ -80,7 +81,7 @@ pub fn all_endpoints<F: Fetch>(
pages.insert("proxy".into(), ProxyPac::boxed(ui_address.clone(), dapps_domain));
pages.insert(WEB_PATH.into(), Web::boxed(ui_address.clone(), web_proxy_tokens.clone(), remote.clone(), fetch.clone()));

Arc::new(pages)
Arc::new(RwLock::new(pages))
}

fn insert<T : WebApp + Default + 'static>(pages: &mut BTreeMap<String, Box<Endpoint>>, id: &str, embed_at: Embeddable) {
Expand Down
3 changes: 2 additions & 1 deletion dapps/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
//! URL Endpoint traits

use std::sync::Arc;
use parking_lot::RwLock;
use std::collections::BTreeMap;

use hyper::{self, server, net};
Expand All @@ -39,7 +40,7 @@ pub struct EndpointInfo {
pub icon_url: String,
}

pub type Endpoints = Arc<BTreeMap<String, Box<Endpoint>>>;
pub type Endpoints = Arc<RwLock<BTreeMap<String, Box<Endpoint>>>>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why add RwLock if it's only read through? doesn't seem to need any lock at all

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the end goal is to push to the BTreeMap new dapp entries as a js developer adds. Currently you have to restart parity to get the new dapp.

pub type Handler = server::Handler<net::HttpStream> + Send;

pub trait Endpoint : Send + Sync {
Expand Down
3 changes: 2 additions & 1 deletion dapps/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ extern crate parity_dapps_glue as parity_dapps;
extern crate parity_hash_fetch as hash_fetch;
extern crate parity_reactor;
extern crate parity_ui;
extern crate parking_lot;

#[macro_use]
extern crate log;
Expand Down Expand Up @@ -106,7 +107,7 @@ pub struct Endpoints {
impl Endpoints {
/// Returns a current list of app endpoints.
pub fn list(&self) -> Vec<apps::App> {
self.endpoints.iter().filter_map(|(ref k, ref e)| {
self.endpoints.read().iter().filter_map(|(ref k, ref e)| {
e.info().map(|ref info| apps::App::from_info(k, info))
}).collect()
}
Expand Down
8 changes: 5 additions & 3 deletions dapps/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,17 @@ impl http::RequestMiddleware for Router {
let is_get_request = *req.method() == hyper::Method::Get;
let is_head_request = *req.method() == hyper::Method::Head;

info!(target: "dapps", "Routing request to {:?}. Details: {:?}", url, req);
trace!(target: "dapps", "Routing request to {:?}. Details: {:?}", url, req);
let endpoints = self.endpoints.as_ref().map(|endpoints| endpoints.read());

let control = control.clone();
debug!(target: "dapps", "Handling endpoint request: {:?}", endpoint);
let handler: Option<Box<Handler>> = match (endpoint.0, endpoint.1, referer) {
// Handle invalid web requests that we can recover from
(ref path, SpecialEndpoint::None, Some((ref referer, ref referer_url)))
if referer.app_id == apps::WEB_PATH
&& self.endpoints.as_ref().map(|ep| ep.contains_key(apps::WEB_PATH)).unwrap_or(false)
&& endpoints.as_ref().map(|ep| ep.contains_key(apps::WEB_PATH)).unwrap_or(false)
&& !is_web_endpoint(path)
=>
{
Expand All @@ -87,9 +89,9 @@ impl http::RequestMiddleware for Router {
.map(|special| special.to_async_handler(path.clone().unwrap_or_default(), control))
},
// Then delegate to dapp
(Some(ref path), _, _) if self.endpoints.as_ref().map(|ep| ep.contains_key(&path.app_id)).unwrap_or(false) => {
(Some(ref path), _, _) if endpoints.as_ref().map(|ep| ep.contains_key(&path.app_id)).unwrap_or(false) => {
trace!(target: "dapps", "Resolving to local/builtin dapp.");
Some(self.endpoints
Some(endpoints
.as_ref()
.expect("endpoints known to be set; qed")
.get(&path.app_id)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems that refreshing on 404 is gone now, so it's only manual afaict.

Expand Down