Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
cbf85d45
Commit
cbf85d45
authored
13 years ago
by
mcmlxxix
Browse files
Options
Downloads
Patches
Plain Diff
distribute updates on client subscribe/unsubscribe for user presence.
pass socket to release instead of descriptor.
parent
406bc09c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
exec/load/json-db.js
+50
-23
50 additions, 23 deletions
exec/load/json-db.js
with
50 additions
and
23 deletions
exec/load/json-db.js
+
50
−
23
View file @
cbf85d45
...
...
@@ -98,6 +98,7 @@ function JSONdb (fileName) {
if
(
!
this
.
subscriptions
[
client
.
id
][
record
.
location
])
{
record
.
shadow
[
record
.
child_name
].
_subscribers
[
client
.
id
]
=
client
;
this
.
subscriptions
[
client
.
id
][
record
.
location
]
=
record
;
send_subscriber_updates
(
client
,
record
,
"
SUBSCRIBE
"
);
}
else
{
this
.
error
(
client
,
this
.
errors
.
DUPLICATE_SUB
);
...
...
@@ -112,6 +113,7 @@ function JSONdb (fileName) {
delete
this
.
subscriptions
[
client
.
id
][
record
.
location
];
if
(
count
(
this
.
subscriptions
[
client
.
id
])
==
0
)
delete
delete
this
.
subscriptions
[
client
.
id
];
send_subscriber_updates
(
client
,
record
,
"
UNSUBSCRIBE
"
);
}
else
{
this
.
error
(
client
,
this
.
errors
.
INVALID_REQUEST
);
...
...
@@ -192,7 +194,7 @@ function JSONdb (fileName) {
/* if this was a write lock, send an update to all record subscribers */
if
(
client_lock
.
type
==
this
.
settings
.
LOCK_WRITE
)
{
this
.
settings
.
UPDATES
=
true
;
send_updates
(
client
,
record
);
send_
data_
updates
(
client
,
record
);
}
delete
record
.
shadow
[
record
.
child_name
].
_lock
[
client
.
id
];
return
true
;
...
...
@@ -348,15 +350,7 @@ function JSONdb (fileName) {
/* return a list of subscriptions and associated IP address for clients */
this
.
who
=
function
(
client
,
record
)
{
var
data
=
[];
for
each
(
var
s
in
record
.
shadow
[
record
.
child_name
].
_subscribers
)
{
data
.
push
({
id
:
s
.
id
,
nick
:
s
.
nick
,
system
:
s
.
system
});
}
log
(
data
.
toSource
());
var
data
=
get_subscriber_list
(
record
);
send_packet
(
client
,
data
,
"
RESPONSE
"
);
return
true
;
}
...
...
@@ -504,13 +498,13 @@ function JSONdb (fileName) {
};
/* release any locks or subscriptions held by a disconnected client */
this
.
release
=
function
(
client
_id
)
{
if
(
this
.
subscriptions
[
client
_
id
])
{
this
.
release
=
function
(
client
)
{
if
(
this
.
subscriptions
[
client
.
id
])
{
free_prisoner
(
client_id
,
this
.
shadow
);
delete
this
.
subscriptions
[
client
_
id
];
delete
this
.
subscriptions
[
client
.
id
];
}
for
(
var
c
=
0
;
c
<
this
.
queue
.
length
;
c
++
)
{
if
(
this
.
queue
[
c
].
client
.
id
==
client
_
id
)
if
(
this
.
queue
[
c
].
client
.
id
==
client
.
id
)
this
.
queue
.
splice
(
c
--
,
1
);
}
};
...
...
@@ -721,22 +715,23 @@ function JSONdb (fileName) {
}
/* release subscriptions and locks on an object recursively */
function
free_prisoner
(
client
_id
,
shadow
)
{
function
free_prisoner
(
client
,
shadow
)
{
if
(
shadow
.
_lock
)
{
if
(
shadow
.
_lock
[
client
_
id
])
{
log
(
LOG_DEBUG
,
"
releasing lock:
"
+
client
_
id
);
delete
shadow
.
_lock
[
client
_
id
];
if
(
shadow
.
_lock
[
client
.
id
])
{
log
(
LOG_DEBUG
,
"
releasing lock:
"
+
client
.
id
);
delete
shadow
.
_lock
[
client
.
id
];
}
}
if
(
shadow
.
_subscribers
)
{
if
(
shadow
.
_subscribers
[
client_id
])
{
log
(
LOG_DEBUG
,
"
releasing subscriber:
"
+
client_id
);
delete
shadow
.
_subscribers
[
client_id
];
if
(
shadow
.
_subscribers
[
client
.
id
])
{
log
(
LOG_DEBUG
,
"
releasing subscriber:
"
+
client
.
id
);
delete
shadow
.
_subscribers
[
client
.
id
];
send_subscriber_updates
(
client
,
record
,
"
UNSUBSCRIBE
"
);
}
}
for
(
var
s
in
shadow
)
{
if
(
typeof
shadow
[
s
]
==
"
object
"
)
free_prisoner
(
client
_
id
,
shadow
[
s
]);
free_prisoner
(
client
.
id
,
shadow
[
s
]);
}
}
...
...
@@ -770,7 +765,7 @@ function JSONdb (fileName) {
}
/* send updates of this object to all subscribers */
function
send_updates
(
client
,
record
)
{
function
send_
data_
updates
(
client
,
record
)
{
for
each
(
var
c
in
record
.
info
.
subscribers
)
{
/* do not send updates to request originator */
if
(
c
.
id
==
client
.
id
)
...
...
@@ -782,6 +777,38 @@ function JSONdb (fileName) {
send_packet
(
c
,
data
,
"
UPDATE
"
);
}
}
/* send update of client subscription to all subscribers */
function
send_subscriber_updates
(
client
,
record
,
oper
)
{
var
data
=
{
oper
:
oper
,
location
:
record
.
location
,
data
:
get_client_info
(
client
)
};
for
each
(
var
c
in
record
.
info
.
subscribers
)
{
/* do not send updates to request originator */
if
(
c
.
id
==
client
.
id
)
continue
;
send_packet
(
c
,
data
,
"
UPDATE
"
);
}
}
function
get_client_info
(
client
)
{
return
{
id
:
client
.
id
,
nick
:
client
.
nick
,
system
:
client
.
system
}
}
/* retrieve a list of subscribers to this record */
function
get_subscriber_list
(
record
)
{
var
data
=
[];
for
each
(
var
s
in
record
.
info
.
subscribers
)
{
data
.
push
(
get_client_info
(
s
));
}
return
data
;
}
/* parse parent object name from a dot-delimited string */
function
get_pname
(
str
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment