wtanaka.praya.gale
Class GaleClient

java.lang.Object
  |
  +--wtanaka.praya.Protocol
        |
        +--wtanaka.praya.gale.GaleClient
All Implemented Interfaces:
java.io.Serializable

public class GaleClient
extends Protocol
implements java.io.Serializable

Protocol subclass for the gale messaging system. A GaleClient multiplexes a single connection to a server using any number of gale session objects.

Return to Sourceforge or the Praya Homepage

Version:
$Name: $ $Date: 2002/07/14 21:11:56 $
Author:
$Author: wtanaka $
See Also:
Multiplexer, Serialized Form

Field Summary
(package private) static int BACKGROUND_TIMEOUT
          Amount of time in milliseconds to wait for a key response in the background.
static java.lang.String CLASS
           
private static int CONF_GALE_CONNECT_STATUS
           
private static int CONF_GALE_FROM
           
private static int CONF_GALE_ID
           
private static int CONF_GALE_ITEM_COUNT
           
private static int CONF_GALE_PORT
           
private static int CONF_GALE_SERVER
           
private static int CONF_GALE_SUBSCRIBE
           
private static int CONF_GALE_SYS_DIR
           
private  java.lang.String currentServer
           
static java.lang.String DEFAULT_SERVER
           
private  int m_akdCounter
           
private  ConfigItem[] m_configItems
           
private  GaleConnection m_connection
           
private  java.lang.String m_defaultDomain
           
private  java.util.Vector m_inMemoryPrivateKeyList
          Used to augment the list fetched from the disk.
private  Multiplexer m_multiplexer
           
private  int m_pseudoPid
           
private  Status m_status
          Present status.
(package private) static int MAX_TIMEOUT
          Maximum timeout to wait for key response.
private  GaleReadThread myThread
           
private static java.lang.String PREFIX_SESSION_AKD
           
private static java.lang.String s_tty
           
private static java.lang.String SESSION_AKD
           
private static java.lang.String SESSION_MAIN
           
private static java.lang.String SESSION_OWO_AKD
           
private static java.lang.String SESSION_OWO_RECEIPT
           
private static java.lang.String SESSION_RECEIPT
           
private static java.lang.String SESSION_RECIPIENT
           
private static java.lang.String[] STATUS_STRINGS
           
 
Fields inherited from class wtanaka.praya.Protocol
descriptionListeners, iAmGarbage, m_buddyList, m_configPanel, m_currentDescription, m_messageListeners, recipientListeners
 
Constructor Summary
GaleClient()
          Constructor
 
Method Summary
protected  void addRecipient(Recipient r, Status s)
          Adds a recipient to this protocol's buddy list.
private  void addSessions()
           
(package private)  java.lang.String arrayToSpaceSeparated(Location[] array)
          Helper method which converts an array of Location into a space separated String.
(package private)  void assertConnected()
          If we are not connected, throw a NotSentException
private  void broadcastLoginNotice()
           
private  void broadcastLogoutMessage()
           
 void checkForNewMessages(boolean isAutomatic)
          New messages are posted from my thread, so this doesn't need to do anything.
 void connect()
          Connects to the network, if that makes any sense.
 CommandInterface[] consoleCommands()
          Returns a list of commands available through this console.
(package private)  PuffOperation constructOutgoingPuff(Category[] cats, java.lang.String msg)
          Common parts of sendEncrypted() and sendPublic()
 void disconnect()
          Disconnects from the network, if that makes any sense.
(package private)  PuffOperation encryptPuff(PuffOperation puff, Location[] ids)
          encrypts a puff
(package private)  PuffOperation encryptPuff(PuffOperation puff, java.lang.String[] ids)
          Deprecated. use encryptPuff (PuffOperation, Location[]) instead
 void fetchKeyFor(Location location)
          For the given ID, in a new thread, opens a connection to the server, listens for that ID's key, and sends a request out for someone to serve up the key.
private  GalePublicKey fetchWaitGetKey(long timeout, Location id)
           
private  void gale_set(java.lang.String name, java.lang.String value)
           
private  java.lang.String galeConfDir()
           
private  void generateKeys()
          Attempts to generate a signed username@praya.gale.org key.
 ConfigItem[] getConfiguration()
           
(package private)  GaleConnection getConnection()
           
(package private)  java.lang.String getDefaultDomain()
           
 Recipient getDefaultRecipient()
           
(package private)  java.lang.String getFrom()
           
static java.awt.Image getIcon()
           
(package private)  java.lang.String getIdClass()
          Gives the id/class of this GaleClient instance.
(package private)  java.lang.String getIdInstance()
          The correct form for the id/instance fragment is GALE_DOMAIN/HOST/USER/TTY/PID where any "variable" may be replaced with an empty string if it is not applicable.
(package private)  java.lang.String getNoticePresence()
          Gives the notice/presence of this GaleClient instance.
private  NWOSubscriptionList getNWOSubscriptions()
           
private  SubscriptionList getOWOSubscriptions()
           
private  int getPort()
           
static java.lang.String getProtocolDescription()
          Used to describe the class of this protocol, before any instances have been created.
private  java.lang.String getServer()
           
(package private)  java.lang.String getSignAsID()
           
private static java.lang.String getTTY()
           
 boolean isConnected()
          Returns if the protocol is connected right now.
private static void populateTTY()
          Ensures that the s_tty variable is set.
private  java.lang.String[] privateKeyList()
          Gets the list of private keys available.
(package private)  void readConfigurationFile(java.io.BufferedReader reader)
          Reads a gale configuration file.
private  void readUserConf()
           
private  void resubscribeAKD()
           
 void sendEncrypted(Category[] cats, java.lang.String msg, java.lang.String[] ids)
           
 void sendPublic(Category[] cats, java.lang.String msg)
           
 void sendPublic(java.lang.String cat, java.lang.String msg)
          Deprecated. use Category[] version instead
(package private)  void sendPuff(PuffOperation puff)
           
private  void setConnectStatus(boolean connected)
           
private  void setDefaultDomain(java.lang.String domain)
           
private  void setFrom(java.lang.String from)
           
 void setStatus(Status status)
          Sends a message to set the status to the given status.
private  void setSubs(NWOSubscriptionList subs)
           
(package private)  PuffOperation signPuff(PuffOperation puff)
           
(package private)  Location[] spaceSeparatedToArray(java.lang.String spaceSep)
          Helper method which converts a space separated string into an array of Location.
 
Methods inherited from class wtanaka.praya.Protocol
addDescriptionListener, addListener, addRecipientListener, changeRecipientStatus, clearBuddyList, console, fireDescriptionChanged, fireRecipientAppeared, fireRecipientChanged, fireRecipientDisappeared, getBuddies, getConfigPanelInstance, getCurrentDescription, getObjInstance, getStatusForBuddy, initialize, isGarbage, markAsGarbage, pushMessage, readObject, removeDescriptionListener, removeListener, removeRecipient, removeRecipientListener, setCurrentDescription, writeObject
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

m_connection

private GaleConnection m_connection

m_multiplexer

private Multiplexer m_multiplexer

myThread

private GaleReadThread myThread

currentServer

private java.lang.String currentServer

m_akdCounter

private int m_akdCounter

CONF_GALE_ID

private static final int CONF_GALE_ID

CONF_GALE_FROM

private static final int CONF_GALE_FROM

CONF_GALE_SERVER

private static final int CONF_GALE_SERVER

CONF_GALE_PORT

private static final int CONF_GALE_PORT

CONF_GALE_SUBSCRIBE

private static final int CONF_GALE_SUBSCRIBE

CONF_GALE_CONNECT_STATUS

private static final int CONF_GALE_CONNECT_STATUS

CONF_GALE_SYS_DIR

private static final int CONF_GALE_SYS_DIR

CONF_GALE_ITEM_COUNT

private static final int CONF_GALE_ITEM_COUNT

SESSION_MAIN

private static final java.lang.String SESSION_MAIN

SESSION_AKD

private static final java.lang.String SESSION_AKD

SESSION_OWO_AKD

private static final java.lang.String SESSION_OWO_AKD

SESSION_RECEIPT

private static final java.lang.String SESSION_RECEIPT

SESSION_OWO_RECEIPT

private static final java.lang.String SESSION_OWO_RECEIPT

SESSION_RECIPIENT

private static final java.lang.String SESSION_RECIPIENT

PREFIX_SESSION_AKD

private static final java.lang.String PREFIX_SESSION_AKD

DEFAULT_SERVER

public static final java.lang.String DEFAULT_SERVER

m_status

private Status m_status
Present status.

m_defaultDomain

private java.lang.String m_defaultDomain

BACKGROUND_TIMEOUT

static final int BACKGROUND_TIMEOUT
Amount of time in milliseconds to wait for a key response in the background.

MAX_TIMEOUT

static final int MAX_TIMEOUT
Maximum timeout to wait for key response.

m_configItems

private ConfigItem[] m_configItems

STATUS_STRINGS

private static final java.lang.String[] STATUS_STRINGS

CLASS

public static final java.lang.String CLASS

s_tty

private static java.lang.String s_tty

m_pseudoPid

private final int m_pseudoPid

m_inMemoryPrivateKeyList

private java.util.Vector m_inMemoryPrivateKeyList
Used to augment the list fetched from the disk.
Constructor Detail

GaleClient

public GaleClient()
Constructor
Method Detail

resubscribeAKD

private void resubscribeAKD()
                     throws java.io.IOException

generateKeys

private void generateKeys()
                   throws java.io.IOException,
                          java.security.NoSuchAlgorithmException
Attempts to generate a signed username@praya.gale.org key.
Throws:
java.io.IOException - if the signing operation fails.

readUserConf

private void readUserConf()

privateKeyList

private java.lang.String[] privateKeyList()
Gets the list of private keys available.

addSessions

private void addSessions()

getDefaultDomain

java.lang.String getDefaultDomain()

setDefaultDomain

private void setDefaultDomain(java.lang.String domain)

populateTTY

private static void populateTTY()
Ensures that the s_tty variable is set.

getTTY

private static java.lang.String getTTY()

getIdInstance

java.lang.String getIdInstance()
The correct form for the id/instance fragment is GALE_DOMAIN/HOST/USER/TTY/PID where any "variable" may be replaced with an empty string if it is not applicable.

getIdClass

java.lang.String getIdClass()
Gives the id/class of this GaleClient instance.
Returns:
the content of CLASS
See Also:
CLASS

getNoticePresence

java.lang.String getNoticePresence()
Gives the notice/presence of this GaleClient instance.

getSignAsID

java.lang.String getSignAsID()

addRecipient

protected void addRecipient(Recipient r,
                            Status s)
Description copied from class: Protocol
Adds a recipient to this protocol's buddy list.
Overrides:
addRecipient in class Protocol

galeConfDir

private java.lang.String galeConfDir()

getConfiguration

public ConfigItem[] getConfiguration()
Overrides:
getConfiguration in class Protocol
Following copied from class: wtanaka.praya.Protocol
Returns:
(self != null) list of configuration items for this protocol.

getPort

private int getPort()

getServer

private java.lang.String getServer()

getFrom

java.lang.String getFrom()

setFrom

private void setFrom(java.lang.String from)

setSubs

private void setSubs(NWOSubscriptionList subs)
              throws java.io.IOException

getNWOSubscriptions

private NWOSubscriptionList getNWOSubscriptions()

getOWOSubscriptions

private SubscriptionList getOWOSubscriptions()

getConnection

GaleConnection getConnection()

setConnectStatus

private void setConnectStatus(boolean connected)

readConfigurationFile

void readConfigurationFile(java.io.BufferedReader reader)
                     throws java.io.IOException
Reads a gale configuration file. Adapted from gale-0.99danger misc_globals.c
Parameters:
reader - the BufferedReader from which to read the configuration file

gale_set

private void gale_set(java.lang.String name,
                      java.lang.String value)
               throws java.io.IOException

checkForNewMessages

public void checkForNewMessages(boolean isAutomatic)
New messages are posted from my thread, so this doesn't need to do anything.
Overrides:
checkForNewMessages in class Protocol
Following copied from class: wtanaka.praya.Protocol
Parameters:
isAutomatic - true if the check is generated automatically with a timer. false if the check is generated manually by the user.

isConnected

public boolean isConnected()
Description copied from class: Protocol
Returns if the protocol is connected right now. Good for telling if you need to call connect() again after the connection dies.
Overrides:
isConnected in class Protocol

connect

public void connect()
             throws java.io.IOException
Description copied from class: Protocol
Connects to the network, if that makes any sense. skip if it does not.
Overrides:
connect in class Protocol
Following copied from class: wtanaka.praya.Protocol
Throws:
java.io.IOException - if the connection fails due to an I/O error.
java.lang.InterruptedException - todo, why does it throw this?

disconnect

public void disconnect()
Description copied from class: Protocol
Disconnects from the network, if that makes any sense. skip if it does not.
Overrides:
disconnect in class Protocol

setStatus

public void setStatus(Status status)
               throws java.io.IOException
Sends a message to set the status to the given status.
Overrides:
setStatus in class Protocol

consoleCommands

public CommandInterface[] consoleCommands()
Description copied from class: Protocol
Returns a list of commands available through this console.
Overrides:
consoleCommands in class Protocol

fetchKeyFor

public void fetchKeyFor(Location location)
                 throws java.io.IOException
For the given ID, in a new thread, opens a connection to the server, listens for that ID's key, and sends a request out for someone to serve up the key. Waits in the thread for BACKGROUND_TIMEOUT milliseconds for the response to come back.

getDefaultRecipient

public Recipient getDefaultRecipient()
Overrides:
getDefaultRecipient in class Protocol

assertConnected

void assertConnected()
               throws NotSentException
If we are not connected, throw a NotSentException

constructOutgoingPuff

PuffOperation constructOutgoingPuff(Category[] cats,
                                    java.lang.String msg)
                              throws java.io.IOException
Common parts of sendEncrypted() and sendPublic()
Parameters:
cat - the category to send on

signPuff

PuffOperation signPuff(PuffOperation puff)
                 throws java.io.IOException

fetchWaitGetKey

private GalePublicKey fetchWaitGetKey(long timeout,
                                      Location id)
                               throws java.io.IOException

encryptPuff

PuffOperation encryptPuff(PuffOperation puff,
                          java.lang.String[] ids)
                    throws java.io.IOException,
                           NotSentException
Deprecated. use encryptPuff (PuffOperation, Location[]) instead


encryptPuff

PuffOperation encryptPuff(PuffOperation puff,
                          Location[] ids)
                    throws java.io.IOException,
                           NotSentException
encrypts a puff

sendEncrypted

public void sendEncrypted(Category[] cats,
                          java.lang.String msg,
                          java.lang.String[] ids)
                   throws java.io.IOException,
                          NotSentException

spaceSeparatedToArray

Location[] spaceSeparatedToArray(java.lang.String spaceSep)
Helper method which converts a space separated string into an array of Location.

arrayToSpaceSeparated

java.lang.String arrayToSpaceSeparated(Location[] array)
Helper method which converts an array of Location into a space separated String.

sendPuff

void sendPuff(PuffOperation puff)
        throws java.io.IOException

sendPublic

public void sendPublic(Category[] cats,
                       java.lang.String msg)
                throws java.io.IOException,
                       NotSentException

sendPublic

public void sendPublic(java.lang.String cat,
                       java.lang.String msg)
                throws java.io.IOException,
                       NotSentException
Deprecated. use Category[] version instead


broadcastLoginNotice

private void broadcastLoginNotice()

broadcastLogoutMessage

private void broadcastLogoutMessage()

getIcon

public static java.awt.Image getIcon()

getProtocolDescription

public static java.lang.String getProtocolDescription()
Used to describe the class of this protocol, before any instances have been created.