Add peer-to-peer file drop

Files move directly between peers over the overlay, with no server in the
path. The receiver listens on the WireGuard address only, so the port is
unreachable from outside the tunnel, and every offer is matched to a known
peer before anything is read.

Consent is the default: an offer carries metadata alone, and no payload
moves until the receiver accepts. Policy is per profile and device-local —
off, ask, or auto-accept, with per-sender exceptions on top.

Policy and history live in the profile's preferences, so removing a profile
takes its file drop state with it. Transfers interrupted by a restart are
settled on load; nothing survives to finish them, and left alone they would
sit in the log as permanently pending.

The Android bindings pull payload bytes through a chunk-returning stream:
gomobile copies a []byte argument into a fresh Java array and never copies
it back, so a fill-my-buffer method would hand back the right length with
no data.
This commit is contained in:
Zoltán Papp
2026-08-16 22:04:38 +02:00
parent 14aab0fc6e
commit 73cffdb702
70 changed files with 11240 additions and 332 deletions
+36
View File
@@ -33,6 +33,9 @@ const (
// subscribers needn't filter the notification firehose. Consumers branch on
// SessionWarning.Final to tell the T-10 event from the T-2 fallback.
EventSessionWarning = "netbird:session:warning"
// EventFileDrop is a typed sibling of EventDaemonNotification for file
// transfer milestones; the payload is a FileDropEvent.
EventFileDrop = "netbird:filedrop"
// StatusDaemonUnavailable is the synthetic Status emitted when the daemon's
// gRPC socket is unreachable. No internal.Status* collides with this label.
@@ -57,6 +60,29 @@ type Emitter interface {
Emit(name string, data ...any) bool
}
// FileDropEvent is the payload of EventFileDrop. Kind is one of "offer",
// "completed", "failed", "withdrawn".
type FileDropEvent struct {
Kind string `json:"kind"`
TransferID string `json:"transferId"`
Message string `json:"message"`
}
func fileDropEventKind(metaKind string) (string, bool) {
switch metaKind {
case proto.MetadataKindFileDropOffer:
return "offer", true
case proto.MetadataKindFileDropCompleted:
return "completed", true
case proto.MetadataKindFileDropFailed:
return "failed", true
case proto.MetadataKindFileDropWithdrawn:
return "withdrawn", true
default:
return "", false
}
}
// SystemEvent is the frontend-facing shape of a daemon SystemEvent.
type SystemEvent struct {
ID string `json:"id"`
@@ -486,6 +512,16 @@ func (s *DaemonFeed) dispatchSystemEvent(ev *proto.SystemEvent) {
}
return
}
if kind, ok := fileDropEventKind(se.Metadata[proto.MetadataKindKey]); ok {
s.emitter.Emit(EventFileDrop, FileDropEvent{
Kind: kind,
TransferID: se.Metadata[proto.MetadataFileDropTransferKey],
Message: se.UserMessage,
})
if se.UserMessage == "" {
return
}
}
s.emitter.Emit(EventDaemonNotification, se)
if warn, ok := authsession.WarningFromMetadata(se.Metadata); ok {
s.emitter.Emit(EventSessionWarning, warn)