peerAdded(
final PeerManager manager,
final Peer peer )
{
IP peerIP = new IP(peer.getIp());
/* if(!Plugin.totalPeer_set.isPresent(peerIP)){
TotalPeerContainer tpc = new TotalPeerContainer(peerIP,Plugin.getPluginInterface().getUtilities().getCurrentSystemTime());
Plugin.totalPeer_set.addToMap(tpc);
}else{
TotalPeerContainer tpc = Plugin.totalPeer_set.getTotalPeerContainer(peerIP);
tpc.setConnectionAttemptsPlusOne();
tpc.setLastConnectionTime(Plugin.getPluginInterface().getUtilities().getCurrentSystemTime());
if(tpc.rule1(peer.getPercentDoneInThousandNotation())){
try {
makeIPFilterRule(peer.getIp(),getPeerID(peer.getId()),peer.getClient(),manager.getDownload().getName(),"r255,g255,b255");
} catch (DownloadException e) {
e.printStackTrace();
}
}
}
*/
peer.addListener(new PeerListener2(){
public void eventOccurred(PeerEvent event) {
if(event.getType() == PeerEvent.ET_STATE_CHANGED){
if(Plugin.areRulesPaused) return;
if(((Integer)event.getData()).intValue() == Peer.TRANSFERING){
try{
if(Plugin.getPluginInterface().getPluginconfig().getPluginBooleanParameter("Stuffer_Block_Seeder",false)){
System.out.println(" % done: " + peer.getPercentDoneInThousandNotation());
if(peer.isSeed() || peer.getPercentDoneInThousandNotation() == 1000){
//System.out.println(" % done: " + peer.getPercentDoneInThousandNotation());
String color = Plugin.getPluginInterface().getPluginconfig().getPluginStringParameter("Stuffer_Block_Seeder_Color","r255g0b0");
//System.out.println("Seeder Color: " + color);
if(!color.equalsIgnoreCase("null")){
String peerID = getPeerID(peer.getId());
String clientName = peer.getClient();
// peer.setSnubbed(true);
makeIPFilterRule(peer.getIp(),"Seeder: " + peerID,clientName + " Seeder",manager.getDownload().getName(), color);
Constants.SEEDER_CLIENT_BLOCKS++;
Plugin.getTab2().renumberMOD_Seeder(false, true);
}
}
}
if(Plugin.getPluginInterface().getPluginconfig().getPluginBooleanParameter("Stuffer_Block_Mods",true)){
Pattern p = Pattern.compile("Azureus (?:[^0-2]|[^01]\\.[^0-2]|[^01]\\.[^01]\\.[^0]|[^01]\\.[^01]\\.[\\d]\\.[^0-2])");
Matcher m = p.matcher(peer.getClient());
if(m.find()){
//System.out.println("Inside RegEx Expression: " + peer.getClient());
if(!peer.supportsMessaging()){
String clientName = peer.getClient();
System.out.println("Found MOD client " + clientName + " : " + peer.getIp() + " at " + Utils.getCurrentTime());
try {
if(manager != null){
String color = Plugin.getPluginInterface().getPluginconfig().getPluginStringParameter("Stuffer_Block_Mods_Color","r255g0b0");
//String peerID = Plugin.getPluginInterface().getUtilities().getFormatters().encodeBytesToString(peer.getId());
if(!color.equalsIgnoreCase("null")){
String peerID = getPeerID(peer.getId());
// peer.setSnubbed(true);
makeIPFilterRule(peer.getIp(),"MOD: " + peerID,clientName + " MOD",manager.getDownload().getName(), color);
Constants.MOD_CLIENT_BLOCKS++;
Plugin.getTab2().renumberMOD_Seeder(true,false);
}
}
} catch (DownloadException e) {
e.printStackTrace();
}
}
}
}
}catch(Exception e){
e.printStackTrace();
}
try {
if(manager != null){
String clientName = peer.getClient();
String color = mainRuleRun(clientName,manager.isSuperSeeding(), manager.getDownload().getState());
if(!color.equalsIgnoreCase("null")){
String peerID = getPeerID(peer.getId());
/*String peerID;
try {
peerID = new String(peer.getId(),"ISO-8859-1");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
peerID = "Normal Peer";
}*/
//String peerID = Plugin.getPluginInterface().getUtilities().getFormatters().encodeBytesToString(peer.getId());
//peer.setSnubbed(true);
makeIPFilterRule(peer.getIp(),peerID,clientName,manager.getDownload().getName(), color);
}
}
} catch (DownloadException e) {
e.printStackTrace();
}
}
}else if(event.getType() == PeerEvent.ET_BAD_CHUNK){
System.out.println(" sentBadChunk listener has been triggered by " + peer.getIp() + " : " + peer.getClient());
/*if(arg1 >= 1){
System.out.println("Peer has sent a bad chunk: " + peer.getClient() + peer.getIp());
if(Plugin.getPluginInterface().getPluginconfig().getPluginBooleanParameter("Stuffer_Block_Bad",true)){
try {
String color = Plugin.getPluginInterface().getPluginconfig().getPluginStringParameter("Stuffer_Block_Bad_Color","r0g255b0");
if(!color.equalsIgnoreCase("null")){
makeIPFilterRule(peer.getIp(),"Bad Data Peer",peer.getClient(),manager.getDownload().getName(), color);
Constants.BAD_CLIENT_BLOCKS++;
Tab2Utilities.renumberMOD_BAD(false,true);
}
} catch (DownloadException e) {
e.printStackTrace();
}
}
}*/
}
}//End of Event Occurred
});
}
public void
peerRemoved(
PeerManager manager,
Peer peer )
{
IP peerIP = new IP(peer.getIp());
/* TotalPeerContainer tpc = Plugin.totalPeer_set.getTotalPeerContainer(peerIP);
if(tpc != null){
tpc.setDisconnectsPlusOne();
tpc.setPercentDone(peer.getPercentDoneInThousandNotation());
}*/