@@ -58,19 +58,35 @@ public NetworkDiscovery() {
58
58
59
59
@ Override
60
60
public List <BoardPort > discovery () {
61
- List <BoardPort > ports = clonePortsList ();
62
- Iterator <BoardPort > iterator = ports .iterator ();
63
- while (iterator .hasNext ()) {
61
+ List <BoardPort > boardPorts = clonePortsList ();
62
+ Iterator <BoardPort > boardPortIterator = boardPorts .iterator ();
63
+ while (boardPortIterator .hasNext ()) {
64
64
try {
65
- BoardPort board = iterator .next ();
66
- if (!NetUtils .isReachable (InetAddress .getByName (board .getAddress ()), Integer .parseInt (board .getPrefs ().get ("port" )))) {
67
- iterator .remove ();
65
+ BoardPort board = boardPortIterator .next ();
66
+
67
+ InetAddress inetAddress = InetAddress .getByName (board .getAddress ());
68
+ int broadcastedPort = Integer .valueOf (board .getPrefs ().get ("port" ));
69
+
70
+ List <Integer > ports = new LinkedList <Integer >();
71
+ ports .add (broadcastedPort );
72
+
73
+ //dirty code: allows non up to date yuns to be discovered. Newer yuns will broadcast port 22
74
+ if (broadcastedPort == 80 ) {
75
+ ports .add (0 , 22 );
76
+ }
77
+
78
+ boolean reachable = false ;
79
+ for (Integer port : ports ) {
80
+ reachable = reachable || NetUtils .isReachable (inetAddress , port );
81
+ }
82
+ if (!reachable ) {
83
+ boardPortIterator .remove ();
68
84
}
69
85
} catch (UnknownHostException e ) {
70
- iterator .remove ();
86
+ boardPortIterator .remove ();
71
87
}
72
88
}
73
- return ports ;
89
+ return boardPorts ;
74
90
}
75
91
76
92
private List <BoardPort > clonePortsList () {
0 commit comments