|
|
|
|
@ -388,52 +388,12 @@ func (i *jsIPN) run(jsCallbacks js.Value) { |
|
|
|
|
log.Printf("Could not generate JSON netmap: %v", err) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if n.Prefs != nil && n.Prefs.Valid() { |
|
|
|
|
if n.Prefs.Valid() { |
|
|
|
|
jsCallbacks.Call("notifyExitNode", string(n.Prefs.ExitNodeID())) |
|
|
|
|
} |
|
|
|
|
if n.BrowseToURL != nil { |
|
|
|
|
jsCallbacks.Call("notifyBrowseToURL", *n.BrowseToURL) |
|
|
|
|
} |
|
|
|
|
if n.FilesWaiting != nil { |
|
|
|
|
jsCallbacks.Call("notifyFilesWaiting") |
|
|
|
|
} |
|
|
|
|
if n.IncomingFiles != nil { |
|
|
|
|
files := make([]jsIncomingFile, len(n.IncomingFiles)) |
|
|
|
|
for i, f := range n.IncomingFiles { |
|
|
|
|
files[i] = jsIncomingFile{ |
|
|
|
|
Name: f.Name, |
|
|
|
|
Started: f.Started.UnixMilli(), |
|
|
|
|
DeclaredSize: f.DeclaredSize, |
|
|
|
|
Received: f.Received, |
|
|
|
|
Done: f.Done, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if b, err := json.Marshal(files); err == nil { |
|
|
|
|
jsCallbacks.Call("notifyIncomingFiles", string(b)) |
|
|
|
|
} else { |
|
|
|
|
log.Printf("could not marshal IncomingFiles: %v", err) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if n.OutgoingFiles != nil { |
|
|
|
|
files := make([]jsOutgoingFile, len(n.OutgoingFiles)) |
|
|
|
|
for i, f := range n.OutgoingFiles { |
|
|
|
|
files[i] = jsOutgoingFile{ |
|
|
|
|
ID: f.ID, |
|
|
|
|
PeerID: string(f.PeerID), |
|
|
|
|
Name: f.Name, |
|
|
|
|
Started: f.Started.UnixMilli(), |
|
|
|
|
DeclaredSize: f.DeclaredSize, |
|
|
|
|
Sent: f.Sent, |
|
|
|
|
Finished: f.Finished, |
|
|
|
|
Succeeded: f.Succeeded, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if b, err := json.Marshal(files); err == nil { |
|
|
|
|
jsCallbacks.Call("notifyOutgoingFiles", string(b)) |
|
|
|
|
} else { |
|
|
|
|
log.Printf("could not marshal OutgoingFiles: %v", err) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
go func() { |
|
|
|
|
@ -961,29 +921,6 @@ func (w termWriter) Write(p []byte) (n int, err error) { |
|
|
|
|
return len(p), nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// jsIncomingFile is the JSON representation of an in-progress inbound file
|
|
|
|
|
// transfer sent to the notifyIncomingFiles callback.
|
|
|
|
|
type jsIncomingFile struct { |
|
|
|
|
Name string `json:"name"` |
|
|
|
|
Started int64 `json:"started"` // Unix milliseconds; use new Date(started) in JS
|
|
|
|
|
DeclaredSize int64 `json:"declaredSize"` // -1 if unknown
|
|
|
|
|
Received int64 `json:"received"` // bytes received so far
|
|
|
|
|
Done bool `json:"done"` // true once the file has been fully received
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// jsOutgoingFile is the JSON representation of an outgoing file transfer
|
|
|
|
|
// sent to the notifyOutgoingFiles callback.
|
|
|
|
|
type jsOutgoingFile struct { |
|
|
|
|
ID string `json:"id"` |
|
|
|
|
PeerID string `json:"peerID"` |
|
|
|
|
Name string `json:"name"` |
|
|
|
|
Started int64 `json:"started"` // Unix milliseconds
|
|
|
|
|
DeclaredSize int64 `json:"declaredSize"` // -1 if unknown
|
|
|
|
|
Sent int64 `json:"sent"` // bytes sent so far
|
|
|
|
|
Finished bool `json:"finished"` |
|
|
|
|
Succeeded bool `json:"succeeded"` // only meaningful when finished
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type jsNetMap struct { |
|
|
|
|
Self jsNetMapSelfNode `json:"self"` |
|
|
|
|
Peers []jsNetMapPeerNode `json:"peers"` |
|
|
|
|
|