src/com/shrewdify/diaroser/impl/PeerImpl.java
@Override
	public byte[] processPeerRequest(byte b[]) throws IOException, NoSpaceException  {
		log.debug("Processing Exchange");
		//System.out.println("------ exchange");
		HashSet<Avp> avpset = new HashSet<Avp>();
		byte temp[] = Arrays.copyOfRange(b, Constants.ZERO, Constants.TWENTY);
		Hashtable<Integer, Avp> hs = par.decodeAvpSet(b, Constants.TWENTY);
		String realm = new String(hs.get(Dictionary.ORIGIN_REALM).rawData);
		int authappid = par.bytesToInt(hs.get(Dictionary.AUTH_APPLICATION_ID).rawData);
		uri = new String(hs.get(Dictionary.ORIGIN_HOST).rawData);
		if (realm.equals(Config.realm) && authappid == 4) {

			avpset = par.copyforResponse(Constants.ZERO, Constants.SUCCESS_CODE, hs);
			Avp a = hs.get(Dictionary.ORIGIN_HOST);
			a.rawData = Config.uri.getBytes();
			avpset.add(a);
			HashSet<Avp> grouped = new HashSet<Avp>();
			grouped.add(new Avp(Dictionary.VENDOR_ID, (short) Constants.EIGHTY, Constants.ZERO, par.int32ToBytes(10415)));
			grouped.add(hs.get(Dictionary.AUTH_APPLICATION_ID));
			a = new Avp(Dictionary.VENDOR_SPECIFIC_APPLICATION_ID, (short) Constants.EIGHTY, Constants.ZERO, null);
			a.addSetAvp(grouped);
			avpset.add(a);
			log.debug("Processed Exchange Request");
			flag=true;
			return par.merge(par.encodeAvpSet(avpset), temp);
		}
		else{
			if(!realm.equals(Config.realm)){

				//	System.out.println("error");
				avpset = par.copyforResponse(Constants.ZERO, Constants.UNKNOWNREALM_CODE, hs);
				return par.merge(par.encodeAvpSet(avpset), temp);				
			}
			else{
				avpset = par.copyforResponse(Constants.ZERO, Constants.UNKNOWNAUTHID_CODE, hs);
				return par.merge(par.encodeAvpSet(avpset), temp);
			}
			
		}
		//	/	return null;
	}
/**
	 * 
	 * 
	 * Returns response for the incoming requests. the request are received in bytes. it separates header from bytes and check for Orgin Host, Realm Name and AuthAPPid.
	 *  When Corresponding Match found it add's success code to content or add's the corresponding error code. The Updated Content is returned with header.
	 */
Returns response for the incoming requests. the request are received in bytes. it separates header from bytes and check for Orgin Host, Realm Name and AuthAPPid.
When Corresponding Match found it add's success code to content or add's the corresponding error code. The Updated Content is returned with header.
Returns response for the incoming requests . the request are received in bytes . it separates header from bytes and check for Orgin Host Realm Name and AuthAPPid . When Corresponding Match found it add ' s success code to content or add ' s the corresponding error code . The Updated Content is returned with header .
@Override
	public byte[] processPeerRequest(byte b[]) throws IOException, NoSpaceException  {
		log.debug("Processing Exchange");
		HashSet<Avp> avpset = new HashSet<Avp>();
		byte temp[] = Arrays.copyOfRange(b, Constants.ZERO, Constants.TWENTY);
		Hashtable<Integer, Avp> hs = par.decodeAvpSet(b, Constants.TWENTY);
		String realm = new String(hs.get(Dictionary.ORIGIN_REALM).rawData);
		int authappid = par.bytesToInt(hs.get(Dictionary.AUTH_APPLICATION_ID).rawData);
		uri = new String(hs.get(Dictionary.ORIGIN_HOST).rawData);
		if (realm.equals(Config.realm) && authappid == 4) {
			avpset = par.copyforResponse(Constants.ZERO, Constants.SUCCESS_CODE, hs);
			Avp a = hs.get(Dictionary.ORIGIN_HOST);
			a.rawData = Config.uri.getBytes();
			avpset.add(a);
			HashSet<Avp> grouped = new HashSet<Avp>();
			grouped.add(new Avp(Dictionary.VENDOR_ID, (short) Constants.EIGHTY, Constants.ZERO, par.int32ToBytes(10415)));
			grouped.add(hs.get(Dictionary.AUTH_APPLICATION_ID));
			a = new Avp(Dictionary.VENDOR_SPECIFIC_APPLICATION_ID, (short) Constants.EIGHTY, Constants.ZERO, null);
			a.addSetAvp(grouped);
			avpset.add(a);
			log.debug("Processed Exchange Request");
			flag=true;
			return par.merge(par.encodeAvpSet(avpset), temp);
		}
		else{
			if(!realm.equals(Config.realm)){
				avpset = par.copyforResponse(Constants.ZERO, Constants.UNKNOWNREALM_CODE, hs);
				return par.merge(par.encodeAvpSet(avpset), temp);				
			}
			else{
				avpset = par.copyforResponse(Constants.ZERO, Constants.UNKNOWNAUTHID_CODE, hs);
				return par.merge(par.encodeAvpSet(avpset), temp);
			}
		}
	}
@ Override public byte [ ] processPeerRequest ( byte b [ ] ) throws IOException , NoSpaceException { log . debug ( "Processing Exchange" ) ; HashSet < Avp > avpset = new HashSet < Avp > ( ) ; byte temp [ ] = Arrays . copyOfRange ( b , Constants . ZERO , Constants . TWENTY ) ; Hashtable < Integer , Avp > hs = par . decodeAvpSet ( b , Constants . TWENTY ) ; String realm = new String ( hs . get ( Dictionary . ORIGIN_REALM ) . rawData ) ; int authappid = par . bytesToInt ( hs . get ( Dictionary . AUTH_APPLICATION_ID ) . rawData ) ; uri = new String ( hs . get ( Dictionary . ORIGIN_HOST ) . rawData ) ; if ( realm . equals ( Config . realm ) && authappid == 4 ) { avpset = par . copyforResponse ( Constants . ZERO , Constants . SUCCESS_CODE , hs ) ; Avp a = hs . get ( Dictionary . ORIGIN_HOST ) ; a . rawData = Config . uri . getBytes ( ) ; avpset . add ( a ) ; HashSet < Avp > grouped = new HashSet < Avp > ( ) ; grouped . add ( new Avp ( Dictionary . VENDOR_ID , ( short ) Constants . EIGHTY , Constants . ZERO , par . int32ToBytes ( 10415 ) ) ) ; grouped . add ( hs . get ( Dictionary . AUTH_APPLICATION_ID ) ) ; a = new Avp ( Dictionary . VENDOR_SPECIFIC_APPLICATION_ID , ( short ) Constants . EIGHTY , Constants . ZERO , null ) ; a . addSetAvp ( grouped ) ; avpset . add ( a ) ; log . debug ( "Processed Exchange Request" ) ; flag = true ; return par . merge ( par . encodeAvpSet ( avpset ) , temp ) ; } else { if ( ! realm . equals ( Config . realm ) ) { avpset = par . copyforResponse ( Constants . ZERO , Constants . UNKNOWNREALM_CODE , hs ) ; return par . merge ( par . encodeAvpSet ( avpset ) , temp ) ; } else { avpset = par . copyforResponse ( Constants . ZERO , Constants . UNKNOWNAUTHID_CODE , hs ) ; return par . merge ( par . encodeAvpSet ( avpset ) , temp ) ; } } }
//System.out.println("------ exchange"); //	System.out.println("error"); //	/	return null;