コード例 #1
0
        private void OnCsFileTransferInterruption(CsFileTransferInterruption msg, ClientId id)
        {
            var sender             = clients[id];
            FileTransferSession ft = null;

            if (msg.SessionId != FileTransferId.InvalidId)
            {
                ft = ftsContainer.GetSessionById(msg.SessionId);
            }
            else // client is sender and doesn't have sid yet
            {
                var senderSessions = ftsContainer.GetUserSessions(sender.Login);
                if (senderSessions != null)
                {
                    foreach (var sid in senderSessions)
                    {
                        var s = ftsContainer.GetSessionById(sid);
                        if (s.Token == msg.Token && s.Sender == sender.Login)
                        {
                            ft = s;
                            break;
                        }
                    }
                }
                if (ft == null)
                {
                    Root.Log(LogLevel.Warning, "Server: ignoring file transfer interruption from client {0} " +
                             "- session not found", sender.Login);
                    return;
                }
            }
            string           oppUsername = sender.Login == ft.Sender ? ft.Receiver : ft.Sender;
            SocketClientBase oppClient;

            if (!nameToClient.TryGetValue(oppUsername, out oppClient))
            {
                Root.Log(LogLevel.Warning, "Server: client {0} attempted to send file transfer data " +
                         "to disconnected client {1}", ft.Sender, ft.Receiver);
                // XXX: suspend session (cl is offline)
                return;
            }
            msg.SessionId = ft.Id;
            switch (msg.Int)
            {
            case FileTransferInterruption.Cancel:
            default:
                ft.State = FileTransferState.Cancelled;
                ftsContainer.DeleteSession(ft.Id);
                break;
            }
            if (!SendTo(oppClient.Id, msg))
            {
                // XXX: suspend file transfer session
            }
        }
コード例 #2
0
        public FileTransferSession CreateSession(ulong token, string sender, string receiver,
                                                 byte[] hash, long size)
        {
            var id = new FileTransferId(++lastSid);
            var ft = new FileTransferSession(id, token, sender, receiver, hash, size);

            idToSession.Add(id, ft);
            HashSet <FileTransferId> senderIds, receiverIds;

            if (!nameToId.TryGetValue(sender, out senderIds))
            {
                senderIds = new HashSet <FileTransferId>();
                nameToId.Add(sender, senderIds);
            }
            senderIds.Add(id);
            if (!nameToId.TryGetValue(receiver, out receiverIds))
            {
                receiverIds = new HashSet <FileTransferId>();
                nameToId.Add(receiver, receiverIds);
            }
            receiverIds.Add(id);
            return(ft);
        }