Example #1
0
 /// <summary>
 /// We are sender.
 /// </summary>
 /// <param name="remote"></param>
 /// <param name="data"></param>
 /// <param name="filename"></param>
 public FileTransfer(Contact remote, Stream data, string filename)
     : base(remote.P2PVersionSupported, remote, remote.SelectBestEndPointId())
 {
     _context    = new FTContext(filename, (ulong)data.Length);
     _dataStream = data;
     _sending    = true;
 }
Example #2
0
        /// <summary>
        /// We are receiver.
        /// </summary>
        /// <param name="p2pSession"></param>
        public FileTransfer(P2PSession p2pSession)
            : base(p2pSession)
        {
            _context = new FTContext(Convert.FromBase64String(p2pSession.Invitation.BodyValues["Context"].Value));
            _sending = false;

            _dataStream = null; // Must be set when InvitationReceived
        }
Example #3
0
        public override bool ValidateInvitation(SLPMessage invite)
        {
            bool ret = base.ValidateInvitation(invite);

            try
            {
                FTContext context = new FTContext(Convert.FromBase64String(invite.BodyValues["Context"].Value));

                Trace.WriteLineIf(Settings.TraceSwitch.TraceVerbose,
                                  String.Format("{0} ({1} bytes) (base validate {2})", context.Filename, context.FileSize, ret), GetType().Name);

                return(ret && (!string.IsNullOrEmpty(context.Filename)) && (context.FileSize > 0));
            }
            catch (Exception)
            {
                // We can't parse the context, so refuse the invite
                Trace.WriteLineIf(Settings.TraceSwitch.TraceError,
                                  String.Format("Unable to parse file transfer invite: {0}", invite.ToDebugString()), GetType().Name);

                return(false);
            }
        }
Example #4
0
 /// <summary>
 /// We are sender.
 /// </summary>
 /// <param name="remote"></param>
 /// <param name="data"></param>
 /// <param name="filename"></param>
 public FileTransfer(Contact remote, Stream data, string filename)
     : base(remote.P2PVersionSupported, remote, remote.SelectBestEndPointId())
 {
     _context = new FTContext(filename, (ulong)data.Length);
     _dataStream = data;
     _sending = true;
 }
Example #5
0
        public override bool ValidateInvitation(SLPMessage invite)
        {
            bool ret = base.ValidateInvitation(invite);
            try
            {
                FTContext context = new FTContext(Convert.FromBase64String(invite.BodyValues["Context"].Value));

                Trace.WriteLineIf(Settings.TraceSwitch.TraceVerbose,
                    String.Format("{0} ({1} bytes) (base validate {2})", context.Filename, context.FileSize, ret), GetType().Name);

                return ret && (!string.IsNullOrEmpty(context.Filename)) && (context.FileSize > 0);
            }
            catch (Exception)
            {
                // We can't parse the context, so refuse the invite
                Trace.WriteLineIf(Settings.TraceSwitch.TraceError,
                    String.Format("Unable to parse file transfer invite: {0}", invite.ToDebugString()), GetType().Name);

                return false;
            }
        }
Example #6
0
        /// <summary>
        /// We are receiver.
        /// </summary>
        /// <param name="p2pSession"></param>
        public FileTransfer(P2PSession p2pSession)
            : base(p2pSession)
        {
            _context = new FTContext(Convert.FromBase64String(p2pSession.Invitation.BodyValues["Context"].Value));
            _sending = false;

            _dataStream = null; // Must be set when InvitationReceived
        }