Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
vernemq
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
stack
vernemq
Commits
a929e649
Commit
a929e649
authored
Nov 20, 2018
by
zCaesar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
edit msg count
parent
af9c7f40
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
8 deletions
+10
-8
authhook/auth_on_publish.js
+3
-2
authhook/redis/on_message.js
+6
-6
authhook/redis/on_register.js
+1
-0
No files found.
authhook/auth_on_publish.js
View file @
a929e649
...
@@ -15,11 +15,12 @@ module.exports = function (options = {}) {
...
@@ -15,11 +15,12 @@ module.exports = function (options = {}) {
console
.
log
(
req
.
body
);
console
.
log
(
req
.
body
);
}
}
var
topic
=
req
.
body
.
topic
;
// save redis
// save redis
require
(
'./redis/on_message'
).
on_message_redis
(
req
.
body
.
client_id
,
req
.
body
.
payload
).
then
(
status
=>
{
require
(
'./redis/on_message'
).
on_message_redis
(
req
.
body
.
client_id
,
req
.
body
.
payload
,
topic
).
then
(
status
=>
{
if
(
status
)
{
if
(
status
)
{
var
authstatus
;
var
authstatus
;
var
topic
=
req
.
body
.
topic
;
var
cachekey
=
'pub:'
+
req
.
body
.
client_id
+
':'
+
req
.
body
.
username
+
':'
+
topic
;
var
cachekey
=
'pub:'
+
req
.
body
.
client_id
+
':'
+
req
.
body
.
username
+
':'
+
topic
;
var
authstatus
=
cache
.
get
(
cachekey
);
var
authstatus
=
cache
.
get
(
cachekey
);
...
...
authhook/redis/on_message.js
View file @
a929e649
var
Redis
=
require
(
'ioredis'
)
var
Redis
=
require
(
'ioredis'
)
var
redis
=
new
Redis
()
var
redis
=
new
Redis
()
function
on_message_redis
(
deviceid
,
payload
)
{
// first time to access on authhook auth_on_register
function
on_message_redis
(
deviceid
,
payload
,
topic
)
{
// first time to access on authhook auth_on_register
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
deviceid
.
indexOf
(
'mqtt'
)
===
0
||
deviceid
.
length
!==
36
)
{
if
(
deviceid
.
indexOf
(
'mqtt'
)
===
0
||
deviceid
.
length
!==
36
)
{
console
.
log
(
deviceid
)
console
.
log
(
deviceid
)
resolve
(
true
)
resolve
(
true
)
}
}
else
{
else
{
var
information
=
setValue
(
deviceid
,
payload
)
var
information
=
setValue
(
deviceid
,
payload
,
topic
)
redis
.
hincrby
(
information
.
keys
,
'actual_message_count'
,
1
)
redis
.
hincrby
(
information
.
keys
,
'actual_message_count'
,
1
)
redis
.
hincrby
(
information
.
keys
,
'charged_message_count'
,
information
.
charged_message_count
)
redis
.
hincrby
(
information
.
keys
,
'charged_message_count'
,
information
.
charged_message_count
)
redis
.
hincrby
(
information
.
keys
,
'total_message_size'
,
information
.
total_message_size
)
redis
.
hincrby
(
information
.
keys
,
'total_message_size'
,
information
.
total_message_size
)
...
@@ -25,17 +25,17 @@ function on_message_redis(deviceid, payload) { // first time to access on authho
...
@@ -25,17 +25,17 @@ function on_message_redis(deviceid, payload) { // first time to access on authho
}
}
module
.
exports
.
on_message_redis
=
on_message_redis
module
.
exports
.
on_message_redis
=
on_message_redis
function
setValue
(
deviceid
,
payload
)
{
function
setValue
(
deviceid
,
payload
,
topic
)
{
var
dateNow
=
Math
.
floor
(
Date
.
now
()
/
1000
)
var
dateNow
=
Math
.
floor
(
Date
.
now
()
/
1000
)
var
keys
=
'deviceid:'
+
deviceid
var
keys
=
'deviceid:'
+
deviceid
var
last_publish
=
dateNow
var
last_publish
=
dateNow
var
msg_count_size
=
payload
.
length
*
3
/
4
var
total_message_size
=
(
payload
.
length
+
topic
.
length
)
*
(
3
/
4
)
var
msg_count_size
=
total_message_size
var
charged_message_count
=
1
var
charged_message_count
=
1
while
(
msg_count_size
>
5000
)
{
while
(
msg_count_size
>
5000
)
{
charged_message_count
+=
1
charged_message_count
+=
1
msg_count_size
=
(
payload
.
length
*
3
/
4
)
-
5000
msg_count_size
=
msg_count_size
-
5000
}
}
var
total_message_size
=
payload
.
length
*
3
/
4
return
{
return
{
keys
:
keys
,
keys
:
keys
,
last_publish
:
last_publish
,
last_publish
:
last_publish
,
...
...
authhook/redis/on_register.js
View file @
a929e649
...
@@ -10,6 +10,7 @@ function on_register_redis(deviceid) { // first time to access on authhook auth_
...
@@ -10,6 +10,7 @@ function on_register_redis(deviceid) { // first time to access on authhook auth_
var
information
=
setValue
(
deviceid
)
var
information
=
setValue
(
deviceid
)
redis
.
hdel
(
information
.
keys
,
'offline_on'
)
redis
.
hdel
(
information
.
keys
,
'offline_on'
)
redis
.
hset
(
information
.
keys
,
'status'
,
information
.
status
,
'register_on'
,
information
.
register_on
,
'last_check'
,
information
.
last_check
,
function
(
err
,
res
)
{
redis
.
hset
(
information
.
keys
,
'status'
,
information
.
status
,
'register_on'
,
information
.
register_on
,
'last_check'
,
information
.
last_check
,
function
(
err
,
res
)
{
console
.
log
(
res
)
if
(
!
res
)
{
if
(
!
res
)
{
deviceUsageCount
()
deviceUsageCount
()
resolve
(
!
res
)
// 0 is ok, 1 is no => if ok is 0 then not 0 = 1
resolve
(
!
res
)
// 0 is ok, 1 is no => if ok is 0 then not 0 = 1
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment