Wait until all QUIT command is sent to server before closing the socket
[KiwiIRC.git] / server / irc / connection.js
1 var net = require('net'),
2 tls = require('tls'),
3 util = require('util'),
4 dns = require('dns'),
5 _ = require('lodash'),
6 winston = require('winston'),
7 EventBinder = require('./eventbinder.js'),
8 IrcServer = require('./server.js'),
9 IrcCommands = require('./commands.js'),
10 IrcChannel = require('./channel.js'),
11 IrcUser = require('./user.js'),
12 EE = require('../ee.js'),
13 iconv = require('iconv-lite'),
14 Proxy = require('../proxy.js'),
15 Socks;
16
17
18 // Break the Node.js version down into usable parts
19 var version_values = process.version.substr(1).split('.').map(function (item) {
20 return parseInt(item, 10);
21 });
22
23 // If we have a suitable Nodejs version, bring in the SOCKS functionality
24 if (version_values[1] >= 10) {
25 Socks = require('socksjs');
26 }
27
28 var IrcConnection = function (hostname, port, ssl, nick, user, options, state, con_num) {
29 EE.call(this,{
30 wildcard: true,
31 delimiter: ' '
32 });
33 this.setMaxListeners(0);
34
35 options = options || {};
36
37 // Socket state
38 this.connected = false;
39
40 // If the connection closes and this is false, we reconnect
41 this.requested_disconnect = false;
42
43 // IRCd write buffers (flood controll)
44 this.write_buffer = [];
45
46 // In process of writing the buffer?
47 this.writing_buffer = false;
48
49 // Max number of lines to write a second
50 this.write_buffer_lines_second = 2;
51
52 // If registeration with the IRCd has completed
53 this.registered = false;
54
55 // If we are in the CAP negotiation stage
56 this.cap_negotiation = true;
57
58 // User information
59 this.nick = nick;
60 this.user = user; // Contains users real hostname and address
61 this.username = this.nick.replace(/[^0-9a-zA-Z\-_.\/]/, '');
62 this.gecos = ''; // Users real-name. Uses default from config if empty
63 this.password = options.password || '';
64
65 // Set the passed encoding. or the default if none giving or it fails
66 if (!options.encoding || !this.setEncoding(options.encoding)) {
67 this.setEncoding(global.config.default_encoding);
68 }
69
70 // State object
71 this.state = state;
72
73 // Connection ID in the state
74 this.con_num = con_num;
75
76 // IRC protocol handling
77 this.irc_commands = new IrcCommands.Handler(this);
78
79 // IrcServer object
80 this.server = new IrcServer(this, hostname, port);
81
82 // IrcUser objects
83 this.irc_users = Object.create(null);
84
85 // TODO: use `this.nick` instead of `'*'` when using an IrcUser per nick
86 this.irc_users[this.nick] = new IrcUser(this, '*');
87
88 // IrcChannel objects
89 this.irc_channels = Object.create(null);
90
91 // IRC connection information
92 this.irc_host = {hostname: hostname, port: port};
93 this.ssl = !(!ssl);
94
95 // SOCKS proxy details
96 // TODO: Wildcard matching of hostnames and/or CIDR ranges of IP addresses
97 if ((global.config.socks_proxy && global.config.socks_proxy.enabled) && ((global.config.socks_proxy.all) || (_.contains(global.config.socks_proxy.proxy_hosts, this.irc_host.hostname)))) {
98 this.socks = {
99 host: global.config.socks_proxy.address,
100 port: global.config.socks_proxy.port,
101 user: global.config.socks_proxy.user,
102 pass: global.config.socks_proxy.pass
103 };
104 } else {
105 this.socks = false;
106 }
107
108 // Kiwi proxy info may be set within a server module. {port: 7779, host: 'kiwi.proxy.com', ssl: false}
109 this.proxy = false;
110
111 // Net. interface this connection should be made through
112 this.outgoing_interface = false;
113
114 // Options sent by the IRCd
115 this.options = Object.create(null);
116 this.options.PREFIX = [
117 {symbol: '~', mode: 'q'},
118 {symbol: '&', mode: 'a'},
119 {symbol: '@', mode: 'o'},
120 {symbol: '%', mode: 'h'},
121 {symbol: '+', mode: 'v'}
122 ];
123
124 this.cap = {requested: [], enabled: []};
125
126 // Is SASL supported on the IRCd
127 this.sasl = false;
128
129 // Buffers for data sent from the IRCd
130 this.hold_last = false;
131 this.held_data = null;
132
133 this.applyIrcEvents();
134 };
135 util.inherits(IrcConnection, EE);
136
137 module.exports.IrcConnection = IrcConnection;
138
139
140
141 IrcConnection.prototype.applyIrcEvents = function () {
142 // Listen for events on the IRC connection
143 this.irc_events = {
144 'server * connect': onServerConnect,
145 'channel * join': onChannelJoin,
146
147 // TODO: uncomment when using an IrcUser per nick
148 //'user:*:privmsg': onUserPrivmsg,
149 'user * nick': onUserNick,
150 'channel * part': onUserParts,
151 'channel * quit': onUserParts,
152 'channel * kick': onUserKick
153 };
154
155 EventBinder.bindIrcEvents('', this.irc_events, this, this);
156 };
157
158
159 /**
160 * Start the connection to the IRCd
161 */
162 IrcConnection.prototype.connect = function () {
163 var that = this;
164
165 // The socket connect event to listener for
166 var socket_connect_event_name = 'connect';
167
168 // The destination address
169 var dest_addr;
170 if (this.socks) {
171 dest_addr = this.socks.host;
172 } else if (this.proxy) {
173 dest_addr = this.proxy.host;
174 } else {
175 dest_addr = this.irc_host.hostname;
176 }
177
178 // Make sure we don't already have an open connection
179 this.disposeSocket();
180
181 this.requested_disconnect = false;
182
183 // Get the IP family for the dest_addr (either socks or IRCd destination)
184 getConnectionFamily(dest_addr, function getConnectionFamilyCb(err, family, host) {
185 var outgoing;
186
187 // Decide which net. interface to make the connection through
188 if (that.outgoing_interface) {
189 // An specific interface has been given for this connection
190 outgoing = this.outgoing_interface;
191
192 } else if (global.config.outgoing_address) {
193 // Pick an interface from the config
194 if ((family === 'IPv6') && (global.config.outgoing_address.IPv6)) {
195 outgoing = global.config.outgoing_address.IPv6;
196 } else {
197 outgoing = global.config.outgoing_address.IPv4 || '0.0.0.0';
198
199 // We don't have an IPv6 interface but dest_addr may still resolve to
200 // an IPv4 address. Reset `host` and try connecting anyway, letting it
201 // fail if an IPv4 resolved address is not found
202 host = dest_addr;
203 }
204
205 // If we have an array of interfaces, select a random one
206 if (typeof outgoing !== 'string' && outgoing.length) {
207 outgoing = outgoing[Math.floor(Math.random() * outgoing.length)];
208 }
209
210 // Make sure we have a valid interface address
211 if (typeof outgoing !== 'string') {
212 outgoing = '0.0.0.0';
213 }
214
215 } else {
216 // No config was found so use the default
217 outgoing = '0.0.0.0';
218 }
219
220 // Are we connecting through a SOCKS proxy?
221 if (that.socks) {
222 that.socket = Socks.connect({
223 host: that.irc_host.host,
224 port: that.irc_host.port,
225 ssl: that.ssl,
226 rejectUnauthorized: global.config.reject_unauthorised_certificates
227 }, {host: host,
228 port: that.socks.port,
229 user: that.socks.user,
230 pass: that.socks.pass,
231 localAddress: outgoing
232 });
233
234 } else if (that.proxy) {
235 that.socket = new Proxy.ProxySocket(that.proxy.port, host, {
236 username: that.username,
237 interface: that.proxy.interface
238 }, {ssl: that.proxy.ssl});
239
240 if (that.ssl) {
241 that.socket.connectTls(that.irc_host.port, that.irc_host.hostname);
242 } else {
243 that.socket.connect(that.irc_host.port, that.irc_host.hostname);
244 }
245
246 } else {
247 // No socks connection, connect directly to the IRCd
248
249 if (that.ssl) {
250 that.socket = tls.connect({
251 host: host,
252 port: that.irc_host.port,
253 rejectUnauthorized: global.config.reject_unauthorised_certificates,
254 localAddress: outgoing
255 });
256
257 // We need the raw socket connect event
258 that.socket.socket.on('connect', function() { rawSocketConnect.call(that, this); });
259
260 socket_connect_event_name = 'secureConnect';
261
262 } else {
263 that.socket = net.connect({
264 host: host,
265 port: that.irc_host.port,
266 localAddress: outgoing
267 });
268 }
269 }
270
271 // Apply the socket listeners
272 that.socket.on(socket_connect_event_name, function socketConnectCb() {
273
274 // TLS connections have the actual socket as a property
275 var is_tls = (typeof this.socket !== 'undefined') ?
276 true :
277 false;
278
279 // TLS sockets have already called this
280 if (!is_tls) {
281 rawSocketConnect.call(that, this);
282 }
283
284 that.connected = true;
285
286 socketConnectHandler.call(that);
287 });
288
289 that.socket.on('error', function socketErrorCb(event) {
290 that.emit('error', event);
291 });
292
293 that.socket.on('data', function () {
294 socketOnData.apply(that, arguments);
295 });
296
297 that.socket.on('close', function socketCloseCb(had_error) {
298 // If that.connected is false, we never actually managed to connect
299 var was_connected = that.connected,
300 had_registered = that.server.registered,
301 should_reconnect = false;
302
303 that.connected = false;
304 that.server.reset();
305
306 // Remove this socket form the identd lookup
307 if (that.identd_port_pair) {
308 delete global.clients.port_pairs[that.identd_port_pair];
309 }
310
311 should_reconnect = (!that.requested_disconnect && was_connected && had_registered);
312
313 if (should_reconnect) {
314 that.emit('reconnecting');
315 } else {
316 that.emit('close', had_error);
317 }
318
319 // Close the whole socket down
320 that.disposeSocket();
321
322 // If this socket closing was not expected and we did actually connect and
323 // we did previously completely register on the network, then reconnect
324 if (should_reconnect) {
325 setTimeout(function() {
326 that.connect();
327 }, 3000);
328 }
329 });
330 });
331 };
332
333 /**
334 * Send an event to the client
335 */
336 IrcConnection.prototype.clientEvent = function (event_name, data, callback) {
337 data.connection_id = this.con_num;
338 this.state.sendIrcCommand(event_name, data, callback);
339 };
340
341 /**
342 * Write a line of data to the IRCd
343 * @param data The line of data to be sent
344 * @param force Write the data now, ignoring any write queue
345 */
346 IrcConnection.prototype.write = function (data, force, force_complete_fn) {
347 //ENCODE string to encoding of the server
348 var encoded_buffer = iconv.encode(data + '\r\n', this.encoding);
349
350 if (force) {
351 this.socket.write(encoded_buffer, force_complete_fn);
352 return;
353 }
354
355 this.write_buffer.push(encoded_buffer);
356
357 // Only flush if we're not writing already
358 if (!this.writing_buffer) {
359 this.flushWriteBuffer();
360 }
361 };
362
363
364
365 /**
366 * Flush the write buffer to the server in a throttled fashion
367 */
368 IrcConnection.prototype.flushWriteBuffer = function () {
369
370 // In case the socket closed between writing our queue.. clean up
371 if (!this.connected) {
372 this.write_buffer = [];
373 this.writing_buffer = false;
374 return;
375 }
376
377 this.writing_buffer = true;
378
379 // Disabled write buffer? Send everything we have
380 if (!this.write_buffer_lines_second) {
381 this.write_buffer.forEach(function(buffer) {
382 this.socket.write(buffer);
383 this.write_buffer = null;
384 });
385
386 this.write_buffer = [];
387 this.writing_buffer = false;
388
389 return;
390 }
391
392 // Nothing to write? Stop writing and leave
393 if (this.write_buffer.length === 0) {
394 this.writing_buffer = false;
395 return;
396 }
397
398 this.socket.write(this.write_buffer[0]);
399 this.write_buffer = this.write_buffer.slice(1);
400
401 // Call this function again at some point if we still have data to write
402 if (this.write_buffer.length > 0) {
403 setTimeout(this.flushWriteBuffer.bind(this), 1000 / this.write_buffer_lines_second);
404 } else {
405 // No more buffers to write.. so we've finished
406 this.writing_buffer = false;
407 }
408 };
409
410
411
412 /**
413 * Close the connection to the IRCd after forcing one last line
414 */
415 IrcConnection.prototype.end = function (data) {
416 var that = this;
417
418 if (!this.socket) {
419 return;
420 }
421
422 this.requested_disconnect = true;
423
424 if (data) {
425 // Once the last bit of data has been sent, then re-run this function to close the socket
426 this.write(data, true, function() {
427 that.end();
428 });
429
430 return;
431 }
432
433 this.socket.end();
434 };
435
436
437
438 /**
439 * Check if any server capabilities are enabled
440 */
441 IrcConnection.prototype.capContainsAny = function (caps) {
442 var enabled_caps;
443
444 if (!caps instanceof Array) {
445 caps = [caps];
446 }
447
448 enabled_caps = _.intersection(this.cap.enabled, caps);
449 return enabled_caps.length > 0;
450 };
451
452
453
454 /**
455 * Clean up this IrcConnection instance and any sockets
456 */
457 IrcConnection.prototype.dispose = function () {
458 // If we're still connected, wait until the socket is closed before disposing
459 // so that all the events are still correctly triggered
460 if (this.socket && this.connected) {
461 this.end();
462 return;
463 }
464
465 if (this.socket) {
466 this.disposeSocket();
467 }
468
469 _.each(this.irc_users, function (user) {
470 user.dispose();
471 });
472 _.each(this.irc_channels, function (chan) {
473 chan.dispose();
474 });
475 this.irc_users = undefined;
476 this.irc_channels = undefined;
477
478 this.server.dispose();
479 this.server = undefined;
480
481 this.irc_commands = undefined;
482
483 EventBinder.unbindIrcEvents('', this.irc_events, this);
484
485 this.removeAllListeners();
486 };
487
488
489
490 /**
491 * Clean up any sockets for this IrcConnection
492 */
493 IrcConnection.prototype.disposeSocket = function () {
494 if (this.socket) {
495 this.socket.end();
496 this.socket.removeAllListeners();
497 this.socket = null;
498 }
499 };
500
501 /**
502 * Set a new encoding for this connection
503 * Return true in case of success
504 */
505
506 IrcConnection.prototype.setEncoding = function (encoding) {
507 var encoded_test;
508
509 try {
510 encoded_test = iconv.encode("TEST", encoding);
511 //This test is done to check if this encoding also supports
512 //the ASCII charset required by the IRC protocols
513 //(Avoid the use of base64 or incompatible encodings)
514 if (encoded_test == "TEST") { // jshint ignore:line
515 this.encoding = encoding;
516 return true;
517 }
518 return false;
519 } catch (err) {
520 return false;
521 }
522 };
523
524 function getConnectionFamily(host, callback) {
525 if (net.isIP(host)) {
526 if (net.isIPv4(host)) {
527 callback(null, 'IPv4', host);
528 } else {
529 callback(null, 'IPv6', host);
530 }
531 } else {
532 dns.resolve6(host, function resolve6Cb(err, addresses) {
533 if (!err) {
534 callback(null, 'IPv6', addresses[0]);
535 } else {
536 dns.resolve4(host, function resolve4Cb(err, addresses) {
537 if (!err) {
538 callback(null, 'IPv4',addresses[0]);
539 } else {
540 callback(err);
541 }
542 });
543 }
544 });
545 }
546 }
547
548
549 function onChannelJoin(event) {
550 var chan;
551
552 // Only deal with ourselves joining a channel
553 if (event.nick !== this.nick) {
554 return;
555 }
556
557 // We should only ever get a JOIN command for a channel
558 // we're not already a member of.. but check we don't
559 // have this channel in case something went wrong somewhere
560 // at an earlier point
561 if (!this.irc_channels[event.channel]) {
562 chan = new IrcChannel(this, event.channel);
563 this.irc_channels[event.channel] = chan;
564 chan.irc_events.join.call(chan, event);
565 }
566 }
567
568
569 function onServerConnect(event) {
570 this.nick = event.nick;
571 }
572
573
574 function onUserPrivmsg(event) {
575 var user;
576
577 // Only deal with messages targetted to us
578 if (event.channel !== this.nick) {
579 return;
580 }
581
582 if (!this.irc_users[event.nick]) {
583 user = new IrcUser(this, event.nick);
584 this.irc_users[event.nick] = user;
585 user.irc_events.privmsg.call(user, event);
586 }
587 }
588
589
590 function onUserNick(event) {
591 // Only deal with messages targetted to us
592 if (event.nick !== this.nick) {
593 return;
594 }
595
596 this.nick = event.newnick;
597 }
598
599
600 function onUserParts(event) {
601 // Only deal with ourselves leaving a channel
602 if (event.nick !== this.nick) {
603 return;
604 }
605
606 if (this.irc_channels[event.channel]) {
607 this.irc_channels[event.channel].dispose();
608 delete this.irc_channels[event.channel];
609 }
610 }
611
612 function onUserKick(event){
613 // Only deal with ourselves being kicked from a channel
614 if (event.kicked !== this.nick) {
615 return;
616 }
617
618 if (this.irc_channels[event.channel]) {
619 this.irc_channels[event.channel].dispose();
620 delete this.irc_channels[event.channel];
621 }
622
623 }
624
625
626
627 /**
628 * When a socket connects to an IRCd
629 * May be called before any socket handshake are complete (eg. TLS)
630 */
631 var rawSocketConnect = function(socket) {
632 // Make note of the port numbers for any identd lookups
633 // Nodejs < 0.9.6 has no socket.localPort so check this first
634 if (typeof socket.localPort !== 'undefined') {
635 this.identd_port_pair = socket.localPort.toString() + '_' + socket.remotePort.toString();
636 global.clients.port_pairs[this.identd_port_pair] = this;
637 }
638 };
639
640
641 /**
642 * Handle the socket connect event, starting the IRCd registration
643 */
644 var socketConnectHandler = function () {
645 var that = this,
646 connect_data;
647
648 // Build up data to be used for webirc/etc detection
649 connect_data = {
650 connection: this,
651
652 // Array of lines to be sent to the IRCd before anything else
653 prepend_data: []
654 };
655
656 // Let the webirc/etc detection modify any required parameters
657 connect_data = findWebIrc.call(this, connect_data);
658
659 global.modules.emit('irc authorize', connect_data).done(function ircAuthorizeCb() {
660 var gecos = that.gecos;
661
662 if (!gecos && global.config.default_gecos) {
663 // We don't have a gecos yet, so use the default
664 gecos = global.config.default_gecos.toString().replace('%n', that.nick);
665 gecos = gecos.replace('%h', that.user.hostname);
666
667 } else if (!gecos) {
668 // We don't have a gecos nor a default, so lets set somthing
669 gecos = '[www.kiwiirc.com] ' + that.nick;
670 }
671
672 // Send any initial data for webirc/etc
673 if (connect_data.prepend_data) {
674 _.each(connect_data.prepend_data, function(data) {
675 that.write(data);
676 });
677 }
678
679 that.write('CAP LS');
680
681 if (that.password) {
682 that.write('PASS ' + that.password);
683 }
684
685 that.write('NICK ' + that.nick);
686 that.write('USER ' + that.username + ' 0 0 :' + gecos);
687
688 that.emit('connected');
689 });
690 };
691
692
693
694 /**
695 * Load any WEBIRC or alternative settings for this connection
696 * Called in scope of the IrcConnection instance
697 */
698 function findWebIrc(connect_data) {
699 var webirc_pass = global.config.webirc_pass,
700 ip_as_username = global.config.ip_as_username,
701 tmp;
702
703
704 // Do we have a WEBIRC password for this?
705 if (webirc_pass && webirc_pass[this.irc_host.hostname]) {
706 // Build the WEBIRC line to be sent before IRC registration
707 tmp = 'WEBIRC ' + webirc_pass[this.irc_host.hostname] + ' KiwiIRC ';
708 tmp += this.user.hostname + ' ' + this.user.address;
709
710 connect_data.prepend_data = [tmp];
711 }
712
713
714 // Check if we need to pass the users IP as its username/ident
715 if (ip_as_username && ip_as_username.indexOf(this.irc_host.hostname) > -1) {
716 // Get a hex value of the clients IP
717 this.username = this.user.address.split('.').map(function ipSplitMapCb(i){
718 var hex = parseInt(i, 10).toString(16);
719
720 // Pad out the hex value if it's a single char
721 if (hex.length === 1) {
722 hex = '0' + hex;
723 }
724
725 return hex;
726 }).join('');
727
728 }
729
730 return connect_data;
731 }
732
733
734 /**
735 * Buffer any data we get from the IRCd until we have complete lines.
736 */
737 function socketOnData(data) {
738 var data_pos, // Current position within the data Buffer
739 line_start = 0,
740 lines = [],
741 i,
742 max_buffer_size = 1024; // 1024 bytes is the maximum length of two RFC1459 IRC messages.
743 // May need tweaking when IRCv3 message tags are more widespread
744
745 // Split data chunk into individual lines
746 for (data_pos = 0; data_pos < data.length; data_pos++) {
747 if (data[data_pos] === 0x0A) { // Check if byte is a line feed
748 lines.push(data.slice(line_start, data_pos));
749 line_start = data_pos + 1;
750 }
751 }
752
753 // No complete lines of data? Check to see if buffering the data would exceed the max buffer size
754 if (!lines[0]) {
755 if ((this.held_data ? this.held_data.length : 0 ) + data.length > max_buffer_size) {
756 // Buffering this data would exeed our max buffer size
757 this.emit('error', 'Message buffer too large');
758 this.socket.destroy();
759
760 } else {
761
762 // Append the incomplete line to our held_data and wait for more
763 if (this.held_data) {
764 this.held_data = Buffer.concat([this.held_data, data], this.held_data.length + data.length);
765 } else {
766 this.held_data = data;
767 }
768 }
769
770 // No complete lines to process..
771 return;
772 }
773
774 // If we have an incomplete line held from the previous chunk of data
775 // merge it with the first line from this chunk of data
776 if (this.hold_last && this.held_data !== null) {
777 lines[0] = Buffer.concat([this.held_data, lines[0]], this.held_data.length + lines[0].length);
778 this.hold_last = false;
779 this.held_data = null;
780 }
781
782 // If the last line of data in this chunk is not complete, hold it so
783 // it can be merged with the first line from the next chunk
784 if (line_start < data_pos) {
785 if ((data.length - line_start) > max_buffer_size) {
786 // Buffering this data would exeed our max buffer size
787 this.emit('error', 'Message buffer too large');
788 this.socket.destroy();
789 return;
790 }
791
792 this.hold_last = true;
793 this.held_data = new Buffer(data.length - line_start);
794 data.copy(this.held_data, 0, line_start);
795 }
796
797 // Process our data line by line
798 for (i = 0; i < lines.length; i++) {
799 parseIrcLine.call(this, lines[i]);
800 }
801
802 }
803
804
805
806 /**
807 * The regex that parses a line of data from the IRCd
808 * Deviates from the RFC a little to support the '/' character now used in some
809 * IRCds
810 */
811 var parse_regex = /^(?:(?:(?:@([^ ]+) )?):(?:([^\s!]+)|([^\s!]+)!([^\s@]+)@?([^\s]+)?) )?(\S+)(?: (?!:)(.+?))?(?: :(.*))?$/i;
812
813 function parseIrcLine(buffer_line) {
814 var msg,
815 i,
816 tags = [],
817 tag,
818 line = '',
819 msg_obj;
820
821 // Decode server encoding
822 line = iconv.decode(buffer_line, this.encoding);
823 if (!line) {
824 return;
825 }
826
827 // Parse the complete line, removing any carriage returns
828 msg = parse_regex.exec(line.replace(/^\r+|\r+$/, ''));
829
830 if (!msg) {
831 // The line was not parsed correctly, must be malformed
832 winston.warn('Malformed IRC line: %s', line.replace(/^\r+|\r+$/, ''));
833 return;
834 }
835
836 // Extract any tags (msg[1])
837 if (msg[1]) {
838 tags = msg[1].split(';');
839
840 for (i = 0; i < tags.length; i++) {
841 tag = tags[i].split('=');
842 tags[i] = {tag: tag[0], value: tag[1]};
843 }
844 }
845
846 msg_obj = {
847 tags: tags,
848 prefix: msg[2],
849 nick: msg[3],
850 ident: msg[4],
851 hostname: msg[5] || '',
852 command: msg[6],
853 params: msg[7] ? msg[7].split(/ +/) : []
854 };
855
856 if (msg[8]) {
857 msg_obj.params.push(msg[8].trim());
858 }
859
860 this.irc_commands.dispatch(new IrcCommands.Command(msg_obj.command.toUpperCase(), msg_obj));
861 }