From 78c207c8d1f5be41b1f69a578789a25b4042d19c Mon Sep 17 00:00:00 2001 From: Simo Kinnunen Date: Wed, 14 May 2014 19:12:28 +0900 Subject: [PATCH] Make group timeout configurable. --- lib/cli.js | 16 +++++++++++++++- lib/roles/app.js | 6 +++--- lib/roles/device/plugins/group.js | 2 +- lib/wire/wire.proto | 2 +- .../components/stf/user/group/group-service.js | 16 ++++++++++------ 5 files changed, 30 insertions(+), 12 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index a3ac64cf..6135b9f1 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -39,6 +39,10 @@ program , 'public ip for global access' , String , ip()) + .option('-t, --group-timeout ' + , 'group timeout' + , Number + , 600) .action(function() { var serials = cliutil.allUnknownArgs(arguments) , options = cliutil.lastArg(arguments) @@ -66,6 +70,7 @@ program , '--connect-push', options.connectPush.join(',') , '--ports', ports.join(',') , '--public-ip', options.publicIp + , '--group-timeout', options.groupTimeout ]) } , endpoints: { @@ -98,6 +103,10 @@ program , 'heartbeat interval' , Number , 10000) + .option('-t, --group-timeout ' + , 'group timeout' + , Number + , 600) .action(function(serial, options) { if (!options.connectSub) { this.missingArgument('--connect-sub') @@ -122,6 +131,7 @@ program , push: options.connectPush } , heartbeatInterval: options.heartbeatInterval + , groupTimeout: options.groupTimeout * 1000 // change to ms }) }) @@ -407,7 +417,6 @@ program , ssid: options.ssid , authUrl: options.authUrl , storageUrl: options.storageUrl - , groupTimeout: 600 * 1000 , endpoints: { sub: options.connectSub , push: options.connectPush @@ -520,6 +529,10 @@ program , os.hostname()) .option('-d, --disable-watch' , 'disable watching resources') + .option('-t, --group-timeout ' + , 'group timeout' + , Number + , 600) .action(function() { var log = logger.createLogger('cli:local') , args = arguments @@ -574,6 +587,7 @@ program , '--name', options.provider , '--connect-sub', options.bindDevPub , '--connect-push', options.bindDevPull + , '--group-timeout', options.groupTimeout ].concat(cliutil.allUnknownArgs(args))) // auth-mock diff --git a/lib/roles/app.js b/lib/roles/app.js index 05b2297c..191e29e6 100644 --- a/lib/roles/app.js +++ b/lib/roles/app.js @@ -460,8 +460,8 @@ module.exports = function(options) { , user.name , user.group ) - , options.groupTimeout - , wireutil.toDeviceRequirements(data) + , data.timeout || null + , wireutil.toDeviceRequirements(data.requirements) ) ) ]) @@ -473,7 +473,7 @@ module.exports = function(options) { , wireutil.transaction( responseChannel , new wire.UngroupMessage( - wireutil.toDeviceRequirements(data) + wireutil.toDeviceRequirements(data.requirements) ) ) ]) diff --git a/lib/roles/device/plugins/group.js b/lib/roles/device/plugins/group.js index 007368ab..301062fe 100644 --- a/lib/roles/device/plugins/group.js +++ b/lib/roles/device/plugins/group.js @@ -44,7 +44,7 @@ module.exports = syrup.serial() log.info('Now owned by "%s"', currentGroup.email) log.info('Subscribing to group channel "%s"', currentGroup.group) - channels.register(currentGroup.group, timeout) + channels.register(currentGroup.group, timeout || options.groupTimeout) sub.subscribe(currentGroup.group) push.send([ diff --git a/lib/wire/wire.proto b/lib/wire/wire.proto index 7f082eb2..5a3146d4 100644 --- a/lib/wire/wire.proto +++ b/lib/wire/wire.proto @@ -210,7 +210,7 @@ message OwnerMessage { message GroupMessage { required OwnerMessage owner = 1; - required uint32 timeout = 2; + optional uint32 timeout = 2; repeated DeviceRequirement requirements = 3; } diff --git a/res/app/components/stf/user/group/group-service.js b/res/app/components/stf/user/group/group-service.js index c03671d6..de2659d5 100644 --- a/res/app/components/stf/user/group/group-service.js +++ b/res/app/components/stf/user/group/group-service.js @@ -8,9 +8,11 @@ module.exports = function GroupServiceFactory( groupService.invite = function (device) { var tx = TransactionService.create(device) socket.emit('group.invite', device.channel, tx.channel, { - serial: { - value: device.serial - , match: 'exact' + requirements: { + serial: { + value: device.serial + , match: 'exact' + } } }) return tx.promise.then(function(result) { @@ -24,9 +26,11 @@ module.exports = function GroupServiceFactory( groupService.kick = function (device) { var tx = TransactionService.create(device) socket.emit('group.kick', device.channel, tx.channel, { - serial: { - value: device.serial - , match: 'exact' + requirements: { + serial: { + value: device.serial + , match: 'exact' + } } }) return tx.promise.then(function(result) {