org.walluck.oscar.handlers.filetransfer
Class FileTransfer

java.lang.Object
  extended by org.walluck.oscar.handlers.filetransfer.FileTransfer

public class FileTransfer
extends Object

File transfer code. Oscar File transfer (OFT) and Oscar Direct Connect (ODC). (ODC is also referred to as DirectIM and IM Image.) There are a few static helper functions at the top, then ODC stuff, then ft stuff. I feel like this is a good place to explain OFT, so I'm going to do just that. Each OFT packet has a header type. I guess this is pretty similar to the subtype of a SNAC packet. The type basically tells the other client the meaning of the OFT packet. There are two distinct types of file transfer, which I usually call "sendfile" and "getfile." Sendfile is when you send a file to another AIM user. Getfile is when you share a group of files, and other users request that you send them the files. A typical sendfile file transfer goes like this:

  1. Sender sends a channel 2 ICBM telling the other user that we want to send them a file. At the same time, we open a listener socket (this should be done before sending the ICBM) on some port, and wait for them to connect to us. The ICBM we sent should contain our IP address and the port number that we're listening on.
  2. The receiver connects to the sender on the given IP address and port. After the connection is established, the receiver sends an ICBM signifying that we are ready and waiting.
  3. The sender sends an OFT PROMPT message over the OFT connection.
  4. The receiver of the file sends back an exact copy of this OFT packet, except the cookie is filled in with the cookie from the ICBM. I think this might be an attempt to verify that the user that is connected is actually the guy that we sent the ICBM to. Oh, I've been calling this the ACK.
  5. The sender starts sending raw data across the connection until the entire file has been sent.
  6. The receiver knows the file is finished because the sender sent the file size in an earlier OFT packet. So then the receiver sends the DONE thingy (after filling in the "received" checksum and size) and closes the connection.

Since:
1.0
Version:
1.0
Author:
David Walluck

Constructor Summary
FileTransfer(AIMSession sess)
          Creates a new FileTransfer.
 
Method Summary
static long calculateChecksum(String name, long start, long stop)
          Calculate the checksum for a file with the given name.
 void getFileAccept(byte[] cookie, byte[] rCookie, String screenname, String remoteIPAddress, int remotePort)
          Accept a get getfile.
 void getFileCancel(byte[] cookie, byte[] rCookie, String screenname, String remoteIPAddress, int remotePort)
          Cancel a getfile.
 void getFileRequest(byte[] cookie, String screenname)
          Request a getfile.
 void removeTransfer(byte[] rCookie)
          Remove a file transfer.
 void sendFileAccept(byte[] cookie, byte[] rCookie, String screenname, String remoteIPAddress, int remotePort)
          Accept a file.
 void sendFileCancel(byte[] cookie, byte[] rCookie, String screenname, String remoteIPAddress, int remotePort)
          Cancel a file.
 void sendFileRequest(byte[] cookie, String screenname, int type, int fileCount, int dirSize, String fileName, String message)
          Send a file transfer request.
 void setWantResponse(boolean wantResponse)
          Set the value of wantResponse.
 boolean wantResponse()
          Get the value of wantResponse.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileTransfer

public FileTransfer(AIMSession sess)
Creates a new FileTransfer.

Parameters:
sess - the oscar session
Method Detail

calculateChecksum

public static long calculateChecksum(String name,
                                     long start,
                                     long stop)
                              throws IOException
Calculate the checksum for a file with the given name.

Parameters:
name - the file name
start - the byte to start at
stop - the byte to stop at
Returns:
the checksum
Throws:
IOException - if an error occurs

getFileRequest

public void getFileRequest(byte[] cookie,
                           String screenname)
Request a getfile.

Parameters:
cookie - the cookie
screenname - the screenname

getFileAccept

public void getFileAccept(byte[] cookie,
                          byte[] rCookie,
                          String screenname,
                          String remoteIPAddress,
                          int remotePort)
Accept a get getfile.

Parameters:
cookie - the cookie
rCookie - the remote cookie
screenname - the screenname
remoteIPAddress - the remote IP address
remotePort - the remote port

getFileCancel

public void getFileCancel(byte[] cookie,
                          byte[] rCookie,
                          String screenname,
                          String remoteIPAddress,
                          int remotePort)
Cancel a getfile.

Parameters:
cookie - the cookie
rCookie - the remote cookie
screenname - the screenname
remoteIPAddress - the remote IP address
remotePort - the remote port

sendFileRequest

public void sendFileRequest(byte[] cookie,
                            String screenname,
                            int type,
                            int fileCount,
                            int dirSize,
                            String fileName,
                            String message)
Send a file transfer request.

Parameters:
cookie - the cookie
screenname - the screenname
type - the type
fileCount - the file count
dirSize - the directory size
fileName - the file (or directoy) name
message - the message

sendFileAccept

public void sendFileAccept(byte[] cookie,
                           byte[] rCookie,
                           String screenname,
                           String remoteIPAddress,
                           int remotePort)
Accept a file. We're neither sender nor listener here.

Parameters:
cookie - the cookie
rCookie - the remote cookie
screenname - the screenname
remoteIPAddress - the remote IP address
remotePort - the remote port

sendFileCancel

public void sendFileCancel(byte[] cookie,
                           byte[] rCookie,
                           String screenname,
                           String remoteIPAddress,
                           int remotePort)
Cancel a file.

Parameters:
cookie - the cookie
rCookie - the remote cookie
screenname - the screenname
remoteIPAddress - the remote IP address
remotePort - the remote port

removeTransfer

public void removeTransfer(byte[] rCookie)
Remove a file transfer.

Parameters:
rCookie - the cookie

wantResponse

public boolean wantResponse()
Get the value of wantResponse.

Returns:
value of wantResponse.

setWantResponse

public void setWantResponse(boolean wantResponse)
Set the value of wantResponse.

Parameters:
wantResponse - Value to assign to wantResponse.