@Override public void routeMessage(RoutingMessage message) throws RoutingException { super.routeMessage(message); try { if (message.getType().equalsIgnoreCase(AODVMessage.AODV_MESSAGE)) { AODVMessage aodvMessage = (AODVMessage) message; switch (aodvMessage.getMessageType()) { case RREQ: receiveRREQ((RouteRequest) aodvMessage); break; case RREP: receiveRREP((RouteReply) aodvMessage); break; case RRER: receiveRRER((RouteError) aodvMessage); break; case HELLO: receiveHello((Hello) aodvMessage); break; default: break; } } else { if (message.getType().equalsIgnoreCase(UserDataMessage.class.getCanonicalName())) { Debug.debugMessage((UserDataMessage) message, getMyAddresses(), true, false); if (getMyAddresses().contains(message.getDestinationAddress())) { getReceiver().queueDataMesssage((UserDataMessage) message); } else { if (isBrodcastMessage(message)) { ((UserDataMessage) message).decrementTtl(); getReceiver().queueDataMesssage((UserDataMessage) message); } forwardData(message); } } } } catch (TimeToLiveExpiredException e) { e.printStackTrace(); } catch (NoSuchRouteException e) { e.printStackTrace(); } catch (InvalidRouteException e) { e.printStackTrace(); } }
@Override public void routeMessage(String destinationAddress, JSONObject message) throws RoutingException { List<String> myAddresses = null; if (BuildConfig.DEBUG) { myAddresses = new ArrayList<String>(); myAddresses.add("Prop Node"); } UserDataMessage dataMessage = new UserDataMessage(message); dataMessage.setDestinationAddress(destinationAddress); if (IRouter.destinationIsBroacast(destinationAddress)) { dataMessage.setNextHop(destinationAddress); } sender.queueMyDataMessage(dataMessage); }
@Override public void stop() { super.stop(); if (helloBroadcaster != null) helloBroadcaster.stopBroadcast(); routingTable.stopTimerThread(); }