aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-node/src/meshbay_node/transport/webrtc
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-node/src/meshbay_node/transport/webrtc')
-rw-r--r--packages/meshbay-node/src/meshbay_node/transport/webrtc/transfer_handlers.py28
1 files changed, 24 insertions, 4 deletions
diff --git a/packages/meshbay-node/src/meshbay_node/transport/webrtc/transfer_handlers.py b/packages/meshbay-node/src/meshbay_node/transport/webrtc/transfer_handlers.py
index 78c74d6..11ad9e6 100644
--- a/packages/meshbay-node/src/meshbay_node/transport/webrtc/transfer_handlers.py
+++ b/packages/meshbay-node/src/meshbay_node/transport/webrtc/transfer_handlers.py
@@ -73,7 +73,10 @@ class TransferMixin:
- **`granted`** — a live lease of *this session*, and the transfer is
under the caps it was granted against. The session is checked as well
as the id: a lease belongs to a connection, and touching somebody
- else's would refresh their idle timer.
+ else's would refresh their idle timer. A connection of the same
+ device to the same group counts as this session here (`_shares`),
+ because one connection carries 5 to 6 MB/s whatever the line can
+ do and a client spreads a large download over several.
- **`queued`** — the node has this lease and has not granted it. The
client is jumping its own queue; refused, and no shipped client does
it (the transfer store awaits the grant before it reads a byte).
@@ -89,13 +92,28 @@ class TransferMixin:
if slots is None:
return LEASE_NONE
lease = slots.leases.get(tr)
- if lease is None or lease.session_key != self._registry_key:
+ if lease is None or not self._shares(lease):
return LEASE_NONE
if lease.state != "granted":
return LEASE_QUEUED
slots.touch(tr)
return LEASE_GRANTED
+ def _shares(self, lease) -> bool:
+ """Whether this connection may move bytes under `lease`.
+
+ Its own lease, or one opened by another connection of the same device,
+ for the same member of the same group. The slot was charged to that
+ member when the lease was granted, so a second connection reading under
+ it costs nobody anything they had not already agreed to. It cannot
+ close the lease and is not told its state: those stay the opener's.
+ """
+ if lease.session_key == self._registry_key:
+ return True
+ return bool(lease.device
+ and lease.device == self._pinned_pk
+ and lease.member == (self._group_id or "", self._user_id or ""))
+
def _note_unleased(self, tr: str) -> None:
"""Say once that this connection transferred outside its lease.
@@ -115,7 +133,7 @@ class TransferMixin:
def _account(self, tr: str, nbytes: int) -> None:
slots = self._ctx.get("_transfer_slots")
if slots is not None:
- slots.account(tr, nbytes)
+ slots.account(tr, nbytes, session_key=self._registry_key)
def _transfer_end_line(self, lease, reason: str) -> str:
"""What a transfer moved, how fast, and what its association looked like.
@@ -131,6 +149,8 @@ class TransferMixin:
if lease.moved and lease.elapsed > 0:
line += (f" in {lease.elapsed:.1f} s "
f"({lease.moved / MIB / lease.elapsed:.2f} MB/s)")
+ if len(lease.lanes) > 1:
+ line += f" over {len(lease.lanes)} connections"
owner = (self if lease.session_key == self._registry_key else
next(iter(self._sessions_everywhere(lease.session_key)), None))
return line + sctp_stats.describe(getattr(owner, "_pc", None))
@@ -212,7 +232,7 @@ class TransferMixin:
lease, err = slots.open(
tr=tr, kind=kind, session_key=self._registry_key,
user_id=self._user_id or "", group_id=self._group_id or "",
- bytes=nbytes, chunks=chunks)
+ bytes=nbytes, chunks=chunks, device=self._pinned_pk)
if err:
self._send({"type": "error", "detail": err, "code": err, "tr": tr})
return