1 /*
2  * Created on 13-Feb-2005
3  * Created by Paul Gardner
4  * Copyright (C) Azureus Software, Inc, All Rights Reserved.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17  *
18  */
19 
20 package org.gudy.azureus2.core3.peer;
21 
22 import java.util.*;
23 
24 import org.gudy.azureus2.core3.config.COConfigurationManager;
25 
26 /**
27  * @author parg
28  *
29  */
30 
31 public class
32 PEPeerSource
33 {
34 		/**
35 		 * Class to enumerate the sources of peer connections
36 		 */
37 
38 
39 	// DON'T change these constants as they get serialised!!!!
40 	// (obviously you can add new networks to them).
41 	// If you add to them remember to update the configuration item default for
42 	// "Peer Source Selection Default.<name>" and
43 
44 	// outgoing connections - details how the peer was discovered
45 
46 	public static final String	PS_BT_TRACKER		= "Tracker";
47 	public static final String	PS_DHT				= "DHT";
48 	public static final String	PS_OTHER_PEER		= "PeerExchange";
49 	public static final String	PS_PLUGIN			= "Plugin";
50 
51 		// incoming connections, we don't know much about these apart from the fact that they occurred
52 
53 	public static final String	PS_INCOMING			= "Incoming";
54 
55 	public static final String[]
56 		PS_SOURCES = {
57 			PS_BT_TRACKER,
58 			PS_DHT,
59 			PS_OTHER_PEER,
60 			PS_PLUGIN,
61 			PS_INCOMING,
62 	};
63 
64 	public static boolean
isPeerSourceEnabledByDefault( String ps )65 	isPeerSourceEnabledByDefault(
66 		String	ps )
67 	{
68 		return( COConfigurationManager.getBooleanParameter( "Peer Source Selection Default." + ps ));
69 	}
70 
71 	public static String[]
getDefaultEnabledPeerSources()72 	getDefaultEnabledPeerSources()
73 	{
74 		List	res = new ArrayList();
75 
76 		for (int i=0;i<PS_SOURCES.length;i++){
77 
78 			if ( COConfigurationManager.getBooleanParameter( "Peer Source Selection Default." + PS_SOURCES[i])){
79 
80 				res.add( PS_SOURCES[i]);
81 			}
82 		}
83 
84 		String[]	x = new String[res.size()];
85 
86 		res.toArray( x );
87 
88 		return( x );
89 	}
90 }
91