[Javanetsim-cvs] javaNetSim/core/protocolsuite/tcp_ip Udp.java,1.7,1.8
Status: Beta
Brought to you by:
darkkey
From: Alexander B. <da...@us...> - 2005-11-20 07:55:56
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24230/core/protocolsuite/tcp_ip Modified Files: Udp.java Log Message: Index: Udp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Udp.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Udp.java 19 Nov 2005 21:53:51 -0000 1.7 --- Udp.java 20 Nov 2005 07:55:48 -0000 1.8 *************** *** 138,142 **** private Hashtable PortTable = new Hashtable(); private ProtocolStack mParentStack; ! private static final int PORT_QUANT=100; private static final int PORT_START_NUMBER=3000; --- 138,142 ---- private Hashtable PortTable = new Hashtable(); private ProtocolStack mParentStack; ! private static final int PORT_QUANT=2; //should be 100, only for dbg purposes private static final int PORT_START_NUMBER=3000; *************** *** 160,164 **** for(i=0;i<PORT_QUANT;i++) { ! PortTable.put((PORT_START_NUMBER+i),Elm); // CHECK HERE } } --- 160,164 ---- for(i=0;i<PORT_QUANT;i++) { ! PortTable.put(new Integer((PORT_START_NUMBER+i)),Elm); // CHECK HERE } } *************** *** 208,212 **** PortTable.remove(inPacket.get_destPort()); //delete old element ! PortTable.put((inPacket.get_destPort()),Elm); //hash table update //now we decompose UDP datagram --- 208,212 ---- PortTable.remove(inPacket.get_destPort()); //delete old element ! PortTable.put(new Integer(inPacket.get_destPort()),Elm); //hash table update //now we decompose UDP datagram *************** *** 346,350 **** public int getDefinitePortNumber(Object application,String inDestIPAddress, int indestPort) throws TransportLayerException { ! int number=0; boolean Found=false; boolean Reserved=false; --- 346,350 ---- public int getDefinitePortNumber(Object application,String inDestIPAddress, int indestPort) throws TransportLayerException { ! Integer number = new Integer(0); boolean Found=false; boolean Reserved=false; *************** *** 355,364 **** while ( (LocalPorts.hasMoreElements()) && !(Found) ) ! { ! number = Integer.valueOf( (String)LocalPorts.nextElement() ); Elm = (UDP_HashTableElement) PortTable.get(number); ! if (Elm.application == application) { Found=true; --- 355,373 ---- while ( (LocalPorts.hasMoreElements()) && !(Found) ) ! { ! number = (Integer) LocalPorts.nextElement(); ! Elm = (UDP_HashTableElement) PortTable.get(number); ! int UID1 = -2; ! int UID2 = -1; ! ! if(Elm.application!=null && application!=null){ ! UID1 = ((Application)Elm.application).getUID(); ! UID2 = ((Application)application).getUID(); ! } ! ! if ( UID1 == UID2) { Found=true; *************** *** 392,401 **** if (Elm.PortStatus == 0) //free port { ! Reserved=true; Elm.PortStatus=2; //port will be busy from now Elm.connectedtoIP=inDestIPAddress; ! Elm.connectedtoPort=indestPort; ! PortTable.remove(number+PORT_START_NUMBER); //delete old element ! PortTable.put(number+PORT_START_NUMBER,Elm); //hash table update } number++; --- 401,411 ---- if (Elm.PortStatus == 0) //free port { ! Reserved=true; Elm.PortStatus=2; //port will be busy from now Elm.connectedtoIP=inDestIPAddress; ! Elm.connectedtoPort=indestPort; ! Elm.application = application; //GIFT: UGLY BUG!!!! ! PortTable.remove(new Integer(number+PORT_START_NUMBER)); //delete old element ! PortTable.put(new Integer(number+PORT_START_NUMBER),Elm); //hash table update } number++; *************** *** 450,454 **** Elm = (UDP_HashTableElement) itr.next(); ! if (Elm.application == application) { Found=true; --- 460,472 ---- Elm = (UDP_HashTableElement) itr.next(); ! int UID1 = -2; ! int UID2 = -1; ! ! if(Elm.application!=null && application!=null){ ! UID1 = ((Application)Elm.application).getUID(); ! UID2 = ((Application)application).getUID(); ! } ! ! if ( UID1 == UID2 ) { Found=true; *************** *** 463,467 **** throw new TransportLayerException("UDP Error: no local port reserved for the application: \"" + application.toString() + "\"! Can not find destination port."); } ! return number; } --- 481,485 ---- throw new TransportLayerException("UDP Error: no local port reserved for the application: \"" + application.toString() + "\"! Can not find destination port."); } ! return new Integer(number); } *************** *** 478,482 **** { UDP_HashTableElement Elm = new UDP_HashTableElement(); ! int PortToClose=getApplicationLocalPortNumber(application); if (Elm.PortStatus==1) --- 496,500 ---- { UDP_HashTableElement Elm = new UDP_HashTableElement(); ! Integer PortToClose=getApplicationLocalPortNumber(application); if (Elm.PortStatus==1) *************** *** 504,508 **** { UDP_HashTableElement Elm = new UDP_HashTableElement(); ! int PortToFree=getApplicationLocalPortNumber(application); if (Elm.PortStatus==2) --- 522,526 ---- { UDP_HashTableElement Elm = new UDP_HashTableElement(); ! Integer PortToFree=getApplicationLocalPortNumber(application); if (Elm.PortStatus==2) *************** *** 524,528 **** * @author gift (sourceforge.net user) * @param application application that uses port ! * @param inPort port that the application want to listen to * @return Nothing * @exception TransportLayerException --- 542,546 ---- * @author gift (sourceforge.net user) * @param application application that uses port ! * @param in_Port port that the application want to listen to * @return Nothing * @exception TransportLayerException *************** *** 533,538 **** // else throw new TransportLayerException("UDP Error: port "+ PortToFree +" is not BUSY by the application: \"" + application.toString() + "\"."); ! public void ListenPort(Object application, int inPort) throws TransportLayerException { if (inPort>=0 && inPort<=10000) { --- 551,557 ---- // else throw new TransportLayerException("UDP Error: port "+ PortToFree +" is not BUSY by the application: \"" + application.toString() + "\"."); ! public void ListenPort(Object application, int in_Port) throws TransportLayerException { + Integer inPort = new Integer(in_Port); if (inPort>=0 && inPort<=10000) { *************** *** 596,606 **** Set set = PortTable.keySet(); Iterator itr = set.iterator(); ! UDP_HashTableElement Elm = new UDP_HashTableElement(); ! while ( (itr.hasNext()) && !(Found) ) { ! Elm = (UDP_HashTableElement) itr.next(); ! if (Elm.application == application) { Found=true; --- 615,639 ---- Set set = PortTable.keySet(); Iterator itr = set.iterator(); ! //Enumeration keys = PortTable.elements(); ! //Integer key = null; ! UDP_HashTableElement Elm = null; ! while ( (itr.hasNext()) && !(Found) ) //keys.hasMoreElements() { ! try{ ! //key = new Integer((Integer) keys.nextElement()); ! //Elm = (UDP_HashTableElement) PortTable.get(key); ! Elm = (UDP_HashTableElement) itr.next(); ! }catch(Exception ex){ System.out.println(ex.toString()); } ! int UID1 = -2; ! int UID2 = -1; ! ! if(Elm!=null && application!=null){ ! if(Elm.application!=null) UID1 = ((Application)Elm.application).getUID(); ! UID2 = ((Application)application).getUID(); ! } ! ! if ( UID1 == UID2 ) { Found=true; *************** *** 608,611 **** --- 641,646 ---- dIP=Elm.connectedtoIP; } + + } *************** *** 641,645 **** Elm = (UDP_HashTableElement) PortTable.get(number); ! if (Elm.application == application) { Found=true; --- 676,688 ---- Elm = (UDP_HashTableElement) PortTable.get(number); ! int UID1 = -2; ! int UID2 = -1; ! ! if(Elm.application!=null && application!=null){ ! UID1 = ((Application)Elm.application).getUID(); ! UID2 = ((Application)application).getUID(); ! } ! ! if ( UID1 == UID2 ) { Found=true; |