/** * Send a message to a specified address. * * @param message Pre-formatted message to send. * @param receiverAddress Address to send it to. * @param receiverPort Receiver port. * @throws IOException If there is a problem connecting or sending. */ public void sendMessage( byte message[], InetAddress receiverAddress, int receiverPort, boolean retry) throws IOException { if (message == null || receiverAddress == null) throw new IllegalArgumentException("Null argument"); SSLSocket sock = (SSLSocket) this.stack.ioHandler.sendBytes(receiverAddress, receiverPort, "TLS", message, retry); // // Created a new socket so close the old one and s // Check for null (bug fix sent in by Christophe) if (sock != mySock && sock != null) { try { if (mySock != null) mySock.close(); } catch (IOException ex) { /* ignore */ } mySock = sock; this.myClientInputStream = mySock.getInputStream(); this.myClientOutputStream = mySock.getOutputStream(); // start a new reader on this end of the pipe. Thread mythread = new Thread(this); mythread.setDaemon(true); mythread.setName("TLSMessageChannelThread"); mythread.start(); } }
/** Default constructor. */ protected SIPTransactionStack() { super(); this.transactionTableSize = -1; // a set of methods that result in dialog creation. this.dialogCreatingMethods = new HashSet<String>(); // Standard set of methods that create dialogs. this.dialogCreatingMethods.add(Request.REFER); this.dialogCreatingMethods.add(Request.INVITE); this.dialogCreatingMethods.add(Request.SUBSCRIBE); // Notify may or may not create a dialog. This is handled in // the code. // Create the transaction collections clientTransactions = Collections.synchronizedList(new ArrayList<SIPClientTransaction>()); serverTransactions = Collections.synchronizedList(new ArrayList<SIPServerTransaction>()); // Dialog dable. this.dialogTable = new Hashtable<String, SIPDialog>(); clientTransactionTable = new Hashtable<String, SIPTransaction>(); serverTransactionTable = new Hashtable<String, SIPTransaction>(); // Start the timer event thread. this.timer = new Timer(); this.pendingRecordScanner = new Thread(new PendingRecordScanner(this)); this.pendingRecordScanner.setDaemon(true); this.pendingTransactions = new HashSet<SIPServerTransaction>(); pendingRecords = Collections.synchronizedList(new ArrayList<PendingRecord>()); pendingRecordScanner.setName("PendingRecordScanner"); pendingRecordScanner.start(); // endif // }
/** * Create a new pipelined parser from an existing one. * * @return A new pipelined parser that reads from the same input stream. */ protected Object clone() { PipelinedMsgParser p = new PipelinedMsgParser(); p.rawInputStream = this.rawInputStream; p.sipMessageListener = this.sipMessageListener; Thread mythread = new Thread(p); mythread.setName("PipelineThread"); return p; }
/** * Constructor - takes a datagram packet and a stack structure Extracts the address of the other * from the datagram packet and stashes away the pointer to the passed stack structure. * * @param stack is the shared SIPStack structure * @param messageProcessor is the creating message processor. */ protected UDPMessageChannel(SIPTransactionStack stack, UDPMessageProcessor messageProcessor) { super.messageProcessor = messageProcessor; this.sipStack = stack; Thread mythread = new Thread(this); this.myAddress = messageProcessor.getIpAddress().getHostAddress(); this.myPort = messageProcessor.getPort(); mythread.setName("UDPMessageChannelThread"); mythread.setDaemon(true); mythread.start(); }
/** * Constructor. We create one of these in order to process an incoming message. * * @param stack is the SIP sipStack. * @param messageProcessor is the creating message processor. * @param packet is the incoming datagram packet. */ protected UDPMessageChannel( SIPTransactionStack stack, UDPMessageProcessor messageProcessor, DatagramPacket packet) { this.incomingPacket = packet; super.messageProcessor = messageProcessor; this.sipStack = stack; this.myAddress = messageProcessor.getIpAddress().getHostAddress(); this.myPort = messageProcessor.getPort(); Thread mythread = new Thread(this); mythread.setDaemon(true); mythread.start(); }
/** Re Initialize the stack instance. */ protected void reInit() { super.reInit(); clientTransactions = Collections.synchronizedList(new ArrayList<SIPClientTransaction>()); serverTransactions = Collections.synchronizedList(new ArrayList<SIPServerTransaction>()); pendingTransactions = new HashSet<SIPServerTransaction>(); pendingRecords = Collections.synchronizedList(new ArrayList<PendingRecord>()); clientTransactionTable = new Hashtable<String, SIPTransaction>(); serverTransactionTable = new Hashtable<String, SIPTransaction>(); // Dialog dable. this.dialogTable = new Hashtable<String, SIPDialog>(); this.timer = new Timer(); pendingRecordScanner = new Thread(new PendingRecordScanner(this)); pendingRecordScanner.setDaemon(true); pendingRecordScanner.setName("PendingRecordScanner"); pendingRecordScanner.start(); }
/** * Constructor when we are given a message listener and an input stream (could be a TCP connection * or a file) * * @param sipMessageListener Message listener which has methods that get called back from the * parser when a parse is complete * @param in Input stream from which to read the input. * @param debug Enable/disable tracing or lexical analyser switch. */ public PipelinedMsgParser( SIPMessageListener sipMessageListener, Pipeline in, boolean debug, int maxMessageSize) { this(); this.sipMessageListener = sipMessageListener; rawInputStream = in; this.maxMessageSize = maxMessageSize; mythread = new Thread(this); mythread.setName("PipelineThread-" + getNewUid()); }
/** * Send message to whoever is connected to us. Uses the topmost via address to send to. * * @param msg is the message to send. * @param retry */ private void sendMessage(byte[] msg, boolean retry) throws IOException { SSLSocket sock = (SSLSocket) this.stack.ioHandler.sendBytes( this.peerAddress, this.peerPort, this.peerProtocol, msg, retry); // Created a new socket so close the old one and stick the new // one in its place but dont do this if it is a datagram socket. // (could have replied via udp but received via tcp!). if (sock != mySock && sock != null) { try { if (mySock != null) mySock.close(); } catch (IOException ex) { } mySock = sock; this.myClientInputStream = mySock.getInputStream(); this.myClientOutputStream = mySock.getOutputStream(); Thread thread = new Thread(this); thread.setDaemon(true); thread.setName("TLSMessageChannelThread"); thread.start(); } }
/** * Constructor - gets called from the SIPStack class with a socket on accepting a new client. All * the processing of the message is done here with the stack being freed up to handle new * connections. The sock input is the socket that is returned from the accept. Global data that is * shared by all threads is accessible in the Server structure. * * @param sock Socket from which to read and write messages. The socket is already connected (was * created as a result of an accept). * @param sipStack Ptr to SIP Stack */ protected TLSMessageChannel( SSLSocket sock, SIPMessageStack sipStack, TLSMessageProcessor msgProcessor) throws IOException { if (LogWriter.needsLogging) { sipStack.logWriter.logMessage("creating new TLSMessageChannel "); sipStack.logWriter.logStackTrace(); } mySock = sock; peerAddress = mySock.getInetAddress(); myAddress = sipStack.getHostAddress(); myClientInputStream = mySock.getInputStream(); myClientOutputStream = mySock.getOutputStream(); mythread = new Thread(this); mythread.setDaemon(true); mythread.setName("TLSMessageChannelThread"); // Stash away a pointer to our stack structure. stack = sipStack; this.tlsMessageProcessor = msgProcessor; this.myPort = this.tlsMessageProcessor.getPort(); // Bug report by Vishwashanti Raj Kadiayl super.messageProcessor = msgProcessor; // Can drop this after response is sent potentially. mythread.start(); }
/** Start reading and processing input. */ public void processInput() { mythread.start(); }