cluster._pike
Go to the documentation of this file.
1 /* Copyright (C) 2000-2004 Thomas Bopp, Thorsten Hampel, Ludger Merkens
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * $Id: cluster.pike,v 1.1 2008/03/31 13:39:57 exodusd Exp $
18  */
19 inherit "/kernel/module";
20 #include <macros.h>
21 #include <classes.h>
22 #include <database.h>
23 //! Server Cluster implementation. Keeps track of inter-Server connections
24 //! and a list of servers with certificates.
25 class cluster : public module{
26 public:
27 
28 
29 
30 import Servers;
31 import cert;
32 
33 
34 
35  ServerList list = ServerList();
36  object serverCert;
37 
38 private:
39 private object get_cert()
40 {
41  if ( objectp(serverCert) )
42  return serverCert;
43 
44  object cert = get_module("filepath:tree")->path_to_object("/documents/steam.cer");
45  if ( !objectp(cert) ) {
46  string c = create_cert( ([
47  "country": "Germany",
48  "organization": "Uni Paderborn",
49  "unit": "sTeam",
50  "locality": "Paderborn",
51  "province": "NRW",
52  "name": _Server->get_server_name(),
53  ]) );
54  cert = get_factory(CLASS_DOCUMENT)->execute(([ "name":"steam.cer", ]));
55  cert->set_content(c);
56  cert->move(OBJ("/documents"));
57  }
58  serverCert = cert;
59  return cert;
60 }
61 
62 public:
63 
64 private:
65 void init_module()
66 {
67  add_data_storage(STORE_SERVERS, save_servers, load_servers, 1);
68 }
69 
70 public:
71 
72 object add_server(string name, string hostname, void|string certificate)
73 {
74  Server s = Server(name, hostname, certificate);
75  list->add(s);
76  require_save(STORE_SERVERS);
77  return s;
78 }
79 
80 Server hello(string name, string cert)
81 {
82  Server s = list->get(name);
83  if ( s->verify(cert) )
84  return s;
85  return 0;
86 }
87 
88 ServerList get_serverlist()
89 {
90  return list;
91 }
92 
93 array get_servers()
94 {
95  return list->list_servers();
96 }
97 
98 mixed send_command(string server, int oid, string func, mixed args)
99 {
100 
101 }
102 
103 object build_connection(Server|string s)
104 {
105  if ( stringp(s) )
106  s = list->get(s);
107  object conn = ((program)"/base/client_base.pike")();
108  conn->connect_server(s->get_hostname(), 1900);
109  conn->server_hello(get_cert());
110  list->set_connection(s, conn);
111  return conn;
112 }
113 
114 mapping save_servers()
115 {
116  return list->save();
117 }
118 
119 void load_servers(mapping data)
120 {
121  list->load(data);
122 }
123 
124 string get_identifier() { return "Cluster"; }
125 
126 
127 
128 
129 
130 
131 
132 };