feat: browse your own shares as a peer receives them
The window could show any peer's share tree but never this account's, so "am I actually sharing that?" had no answer short of asking a friend to browse you. The tree is already there; what was missing was feeding it from our own index. B opens it — the same collapsible tree, filter, and navigation the peer browse offers, built from `Shares::directories()`, which is the listing GetShareFileList answers with. So what it shows is what the network sees, not what the config meant to share. r re-scans the disk rather than re-asking a peer, o steps across to the folders that feed it, and nothing here queues a download from ourselves. Attached to a daemon the index lives on the daemon's host, so it comes back over a new `shares.files` method rather than being scanned locally; `shares files [--filter]` prints the same listing headless, through the `emit_listing` that `browse` now shares with it — the two are only comparable while they are built the same way. Two allocation fixes came out of the review, both on paths this reaches: the daemon hands its listing to the DTO instead of deep-copying one it already owns, and `Shares::directories()` allocates its map key once per folder rather than once per file, which the peer-facing serve path has been paying for all along.
This commit is contained in:
@@ -14,8 +14,8 @@ use crate::daemon::proto::{
|
||||
DownloadStartParams, DownloadStarted, Downloads, Event, IntervalSeconds,
|
||||
MemberStats, Members, MessageParams, Messages, Method, PROTOCOL_VERSION,
|
||||
PasswordParams, QueryParams, Request, Response, RoomRef, RpcError,
|
||||
SayParams, SearchResults, Searches, Seconds, SharesStatus, SlotsParams,
|
||||
TransferRef, Uploads, UserRef, UserResult, Watched,
|
||||
SayParams, SearchResults, Searches, Seconds, SharedListing, SharesStatus,
|
||||
SlotsParams, TransferRef, Uploads, UserRef, UserResult, Watched,
|
||||
};
|
||||
use mirror::Mirror;
|
||||
use serde::de::DeserializeOwned;
|
||||
@@ -823,6 +823,18 @@ impl SessionApi for RemoteSession {
|
||||
self.shares().directories
|
||||
}
|
||||
|
||||
// ponytail: a blocking round-trip that carries the whole index — a very
|
||||
// large share is tens of MB of JSON before the next redraw. It is only
|
||||
// ever a keypress, never a frame; if that stops being tolerable, push it
|
||||
// as an event the way `browse.user` answers with `event.browse`.
|
||||
fn shared_listing(&self) -> Vec<SharedDirectory> {
|
||||
self.request::<_, SharedListing>(Method::SharesFiles, ())
|
||||
.map(|listing| {
|
||||
listing.directories.into_iter().map(Into::into).collect()
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn set_shared_directories(&self, directories: Vec<String>) -> Result<()> {
|
||||
self.tell(Method::SharesSet, DirectoriesParams { directories })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user