murmur-rpc 0.0.8 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9c00935a2c1e63c82960fb0c0ec13e844e0e53ec
4
+ data.tar.gz: 07b869391a613277388e2d4789fecd73222d4834
5
+ SHA512:
6
+ metadata.gz: 79c3db87c1b3d776c933fbbcd1fb2d4d8edbdc3b7b40b46c3d8e980b5113609fe0426f410ec3a43562f7c347c922790a0e8737cf4c5a607fa205d2cb6bbb86d7
7
+ data.tar.gz: 078143492c5360ef460553f083f0e80a1c13899bb356ac2cebeb9352805b461c030a0eeea745c80656c02d3accdd82f406c89aa14c3f6170494f67c44d12c2cc
data/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # Murmur RPC Ruby Library
2
+
3
+ This is a rubygem that allows you to connect and manage a murmurd server using the Ice interface. It require the ruby Ice libraries to be installed.
4
+
5
+ ### How to update slice
6
+
7
+ ```
8
+ cd vendor/ice
9
+ wget -O Murmur.ice "https://raw.githubusercontent.com/mumble-voip/mumble/master/src/murmur/Murmur.ice"
10
+ slice2rb Murmur.ice
11
+ ```
@@ -0,0 +1,161 @@
1
+ require 'timeout'
2
+ require 'benchmark'
3
+ require 'Glacier2'
4
+
5
+ require File.join(File.expand_path(File.dirname(__FILE__)), "..", "..", "..", "vendor", "ice", "Murmur.rb")
6
+
7
+ module Murmur
8
+ module Ice
9
+ class ::InvalidMetaException < Exception; end
10
+ class ::Murmur::Ice::InvalidServerException < Exception; end
11
+ class Meta
12
+ def initialize(glacierHost = nil, glacierPort = nil, user = nil, pass = nil, host = "127.0.0.1", port = "6502", icesecret = nil, connect_timeout=nil, idletime = nil)
13
+ ic = nil
14
+ if icesecret and icesecret != ""
15
+ props = ::Ice::createProperties
16
+ props.setProperty "Ice.ImplicitContext", "Shared"
17
+ props.setProperty "Ice.Override.Timeout", connect_timeout.to_s unless connect_timeout == nil
18
+ props.setProperty "Ice.MessageSizeMax", "65536"
19
+ props.setProperty "Ice.Default.EncodingVersion", "1.0"
20
+ idd = ::Ice::InitializationData.new
21
+ idd.properties = props
22
+ ic = ::Ice::initialize idd
23
+ ic.getImplicitContext.put("secret", icesecret)
24
+ else
25
+ ic = ::Ice::initialize
26
+ end
27
+
28
+ if glacierHost and glacierHost != "" then
29
+ @glacierHost = glacierHost
30
+ @glacierPort = glacierPort
31
+ validate_connection(glacierHost, glacierPort)
32
+ prx = ic.stringToProxy("Glacier2/router:tcp -h #{glacierHost} -p #{glacierPort}")
33
+ @router = ::Glacier2::RouterPrx::uncheckedCast(prx).ice_router(nil)
34
+ @session = @router.createSession(user, pass)
35
+ end
36
+ conn = "tcp -h #{host} -p #{port}"
37
+ @meta = add_proxy_router(Murmur::MetaPrx::checkedCast(ic.stringToProxy("Meta:#{conn}")))
38
+ raise "Invalid proxy" unless @meta
39
+
40
+ @servers = {}
41
+ end
42
+
43
+ def destroy
44
+ begin
45
+ @router.destroySession @session unless @router.nil?
46
+ rescue ::Ice::ConnectionLostException
47
+ # Expected - Ice raises this when the connection is terminated. Yay for exceptions as flow control?
48
+ end
49
+ return nil
50
+ end
51
+
52
+ def add_proxy_router(prx)
53
+ @router ? prx.ice_router(@router) : prx
54
+ end
55
+
56
+ def get_server(id)
57
+ @servers[id] ||= Server.new(self, @meta, id)
58
+ end
59
+
60
+ def uncache_server(id)
61
+ @servers[id] = nil
62
+ end
63
+
64
+ def list_servers(only_booted = false)
65
+ method = only_booted ? :getBootedServers : :getAllServers
66
+ @meta.send(method).collect do |server|
67
+ server = add_proxy_router(server)
68
+ @servers[server.id] ||= Server.new(self, @meta, nil, server)
69
+ end
70
+ end
71
+
72
+ def validate
73
+ @meta.getVersion
74
+ return true
75
+ end
76
+
77
+ def new_server(port = nil)
78
+ server = @meta.newServer
79
+ @servers[server.id] = Server.new(self, @meta, nil, add_proxy_router(server))
80
+ end
81
+
82
+ def method_missing(method, *args)
83
+ method = method.to_s
84
+ method.gsub!(/_([a-z])/) { $1.upcase }
85
+ @meta.send method, *args
86
+ end
87
+
88
+ def validate_connection(host, port)
89
+ Timeout::timeout(2) do
90
+ begin
91
+ s = TCPSocket.new(host, port)
92
+ s.close
93
+ rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
94
+ raise InvalidMetaException
95
+ end
96
+ end
97
+ rescue Timeout::Error
98
+ raise InvalidMetaException
99
+ end
100
+ end
101
+
102
+ class Server
103
+ def initialize(host, meta, id = nil, interface = nil)
104
+ @meta = meta
105
+ @host = host
106
+ if id.nil? and interface.nil? then
107
+ raise "Must pass either a server ID or a server interface instance"
108
+ end
109
+ @interface = interface || begin
110
+ server = @meta.getServer(id)
111
+ raise ::Murmur::Ice::InvalidServerException if server.nil?
112
+ host.add_proxy_router(server)
113
+ end
114
+ end
115
+
116
+ def id
117
+ @interface.id
118
+ end
119
+
120
+ def running?
121
+ @interface.isRunning
122
+ end
123
+
124
+ def config
125
+ @config = @meta.getDefaultConf.merge(@interface.getAllConf)
126
+ end
127
+
128
+ def destroy!
129
+ @interface.stop if running?
130
+ @host.uncache_server @interface.id
131
+ @interface.delete
132
+ end
133
+ alias :delete :destroy!
134
+
135
+ def restart!
136
+ @interface.stop if running?
137
+ @interface.start
138
+ @running = nil
139
+ end
140
+
141
+ def [](key)
142
+ config[key]
143
+ end
144
+
145
+ def []=(key, val)
146
+ @interface.setConf(key, val.to_s)
147
+ @config = nil
148
+ end
149
+
150
+ def setConf(key, val)
151
+ self[key] = val
152
+ end
153
+
154
+ def method_missing(method, *args)
155
+ method = method.to_s
156
+ method.gsub!(/_([a-z])/) { $1.upcase }
157
+ @interface.send method, *args
158
+ end
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,3 @@
1
+ module MurmurRPC
2
+ VERSION="0.1.1"
3
+ end
data/lib/murmur-rpc.rb CHANGED
@@ -1,5 +1 @@
1
- require File.dirname(__FILE__) + '/interfaces/ice.rb'
2
-
3
- module MurmurRPC
4
- VERSION="0.0.8"
5
- end
1
+ require 'murmur-rpc/interfaces/ice.rb'
@@ -64,10 +64,27 @@ module Murmur
64
64
  bool tcponly;
65
65
  /** Idle time. This is how many seconds it is since the user last spoke. Other activity is not counted. */
66
66
  int idlesecs;
67
+ /** UDP Ping Average. This is the average ping for the user via UDP over the duration of the connection. */
68
+ float udpPing;
69
+ /** TCP Ping Average. This is the average ping for the user via TCP over the duration of the connection. */
70
+ float tcpPing;
67
71
  };
68
72
 
69
73
  sequence<int> IntList;
70
74
 
75
+ /** A text message between users.
76
+ **/
77
+ struct TextMessage {
78
+ /** Sessions (connected users) who were sent this message. */
79
+ IntList sessions;
80
+ /** Channels who were sent this message. */
81
+ IntList channels;
82
+ /** Trees of channels who were sent this message. */
83
+ IntList trees;
84
+ /** The contents of the message. */
85
+ string text;
86
+ };
87
+
71
88
  /** A channel.
72
89
  **/
73
90
  struct Channel {
@@ -245,6 +262,8 @@ module Murmur
245
262
  exception InvalidCallbackException extends MurmurException {};
246
263
  /** This is thrown when you supply the wrong secret in the calling context. */
247
264
  exception InvalidSecretException extends MurmurException {};
265
+ /** This is thrown when the channel operation would excede the channel nesting limit */
266
+ exception NestingLimitException extends MurmurException {};
248
267
 
249
268
  /** Callback interface for servers. You can supply an implementation of this to receive notification
250
269
  * messages from the server.
@@ -270,6 +289,11 @@ module Murmur
270
289
  * @param state New state of user.
271
290
  */
272
291
  idempotent void userStateChanged(User state);
292
+ /** Called when user writes a text message
293
+ * @param state the User sending the message
294
+ * @param message the TextMessage the user has sent
295
+ */
296
+ idempotent void userTextMessage(User state, TextMessage message);
273
297
  /** Called when a new channel is created.
274
298
  * @param state State of new channel.
275
299
  */
@@ -414,7 +438,10 @@ module Murmur
414
438
  /** Start server. */
415
439
  void start() throws ServerBootedException, ServerFailureException, InvalidSecretException;
416
440
 
417
- /** Stop server. */
441
+ /** Stop server.
442
+ * Note: Server will be restarted on Murmur restart unless explicitly disabled
443
+ * with setConf("boot", false)
444
+ */
418
445
  void stop() throws ServerBootedException, InvalidSecretException;
419
446
 
420
447
  /** Delete server and all it's configuration. */
@@ -550,6 +577,13 @@ module Murmur
550
577
  * @return true if any of the permissions in perm were set for the user.
551
578
  */
552
579
  bool hasPermission(int session, int channelid, int perm) throws ServerBootedException, InvalidSessionException, InvalidChannelException, InvalidSecretException;
580
+
581
+ /** Return users effective permissions
582
+ * @param session Connection ID of user. See {@link User.session}.
583
+ * @param channelid ID of Channel. See {@link Channel.id}.
584
+ * @return bitfield of allowed actions
585
+ */
586
+ idempotent int effectivePermissions(int session, int channelid) throws ServerBootedException, InvalidSessionException, InvalidChannelException, InvalidSecretException;
553
587
 
554
588
  /** Add a context callback. This is done per user, and will add a context menu action for the user.
555
589
  *
@@ -581,7 +615,7 @@ module Murmur
581
615
  * @param state Channel state to set.
582
616
  * @see getChannelState
583
617
  */
584
- idempotent void setChannelState(Channel state) throws ServerBootedException, InvalidChannelException, InvalidSecretException;
618
+ idempotent void setChannelState(Channel state) throws ServerBootedException, InvalidChannelException, InvalidSecretException, NestingLimitException;
585
619
 
586
620
  /** Remove a channel and all its subchannels.
587
621
  * @param channelid ID of Channel. See {@link Channel.id}.
@@ -593,7 +627,7 @@ module Murmur
593
627
  * @param parent Channel ID of parent channel. See {@link Channel.id}.
594
628
  * @return ID of newly created channel.
595
629
  */
596
- int addChannel(string name, int parent) throws ServerBootedException, InvalidChannelException, InvalidSecretException;
630
+ int addChannel(string name, int parent) throws ServerBootedException, InvalidChannelException, InvalidSecretException, NestingLimitException;
597
631
 
598
632
  /** Send text message to channel or a tree of channels.
599
633
  * @param channelid Channel ID of channel to send to. See {@link Channel.id}.