Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Tor Browser
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
The Tor Project
Applications
Tor Browser
Commits
2d3871a1
Verified
Commit
2d3871a1
authored
Jun 16, 2023
by
Pier Angelo Vendrame
Browse files
Options
Downloads
Patches
Plain Diff
fixup! Bug 40933: Add tor-launcher functionality
Small improvements on event registration.
parent
ced99694
Branches
Branches containing commit
No related tags found
1 merge request
!734
Bug 42030: Rebased 13.0 alpha onto Firefox 115.2.0esr
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
toolkit/components/tor-launcher/TorMonitorService.sys.mjs
+54
-57
54 additions, 57 deletions
toolkit/components/tor-launcher/TorMonitorService.sys.mjs
toolkit/components/tor-launcher/TorParsers.sys.mjs
+6
-6
6 additions, 6 deletions
toolkit/components/tor-launcher/TorParsers.sys.mjs
with
60 additions
and
63 deletions
toolkit/components/tor-launcher/TorMonitorService.sys.mjs
+
54
−
57
View file @
2d3871a1
...
...
@@ -52,7 +52,7 @@ const ControlConnTimings = Object.freeze({
*/
export
const
TorMonitorService
=
{
_connection
:
null
,
_event
sToMonitor
:
Object
.
freeze
([
"
STATUS_CLIENT
"
,
"
NOTICE
"
,
"
WARN
"
,
"
ERR
"
])
,
_event
Handlers
:
{}
,
_torLog
:
[],
// Array of objects with date, type, and msg properties.
_startTimeout
:
null
,
...
...
@@ -72,6 +72,17 @@ export const TorMonitorService = {
return
;
}
this
.
_inited
=
true
;
this
.
_eventHandlers
=
new
Map
([
[
"
STATUS_CLIENT
"
,
(
_eventType
,
lines
)
=>
this
.
_processBootstrapStatus
(
lines
[
0
],
false
),
],
[
"
NOTICE
"
,
this
.
_processLog
.
bind
(
this
)],
[
"
WARN
"
,
this
.
_processLog
.
bind
(
this
)],
[
"
ERR
"
,
this
.
_processLog
.
bind
(
this
)],
]);
if
(
this
.
ownsTorDaemon
)
{
this
.
_controlTor
();
}
else
{
...
...
@@ -272,7 +283,7 @@ export const TorMonitorService = {
// TODO: optionally monitor INFO and DEBUG log messages.
let
reply
=
await
conn
.
sendCommand
(
"
SETEVENTS
"
+
this
.
_eventsToMonitor
.
join
(
"
"
)
"
SETEVENTS
"
+
Array
.
from
(
this
.
_eventHandlers
.
keys
())
.
join
(
"
"
)
);
reply
=
TorParsers
.
parseCommandResponse
(
reply
);
if
(
!
TorParsers
.
commandSucceeded
(
reply
))
{
...
...
@@ -297,7 +308,11 @@ export const TorMonitorService = {
}
this
.
_connection
=
conn
;
this
.
_waitForEventData
();
for
(
const
[
type
,
callback
]
of
this
.
_eventHandlers
.
entries
())
{
this
.
_monitorEvent
(
type
,
callback
);
}
return
true
;
},
...
...
@@ -318,15 +333,11 @@ export const TorMonitorService = {
}
},
_waitForEventData
()
{
if
(
!
this
.
_connection
)
{
return
;
}
logger
.
debug
(
"
Start watching events:
"
,
this
.
_eventsToMonitor
);
_monitorEvent
(
type
,
callback
)
{
logger
.
debug
(
`Watching events of type
${
type
}
.`
);
let
replyObj
=
{};
for
(
const
torEvent
of
this
.
_eventsToMonitor
)
{
this
.
_connection
.
watchEvent
(
torEvent
,
type
,
null
,
line
=>
{
if
(
!
line
)
{
...
...
@@ -334,49 +345,33 @@ export const TorMonitorService = {
}
logger
.
debug
(
"
Event response:
"
,
line
);
const
isComplete
=
TorParsers
.
parseReplyLine
(
line
,
replyObj
);
if
(
isComplete
)
{
this
.
_processEventReply
(
replyObj
);
replyObj
=
{};
}
},
true
);
}
},
_processEventReply
(
aReply
)
{
if
(
aReply
.
_parseError
||
!
aReply
.
lineArray
.
length
)
{
if
(
!
isComplete
||
replyObj
.
_parseError
||
!
replyObj
.
lineArray
.
length
)
{
return
;
}
if
(
aReply
.
statusCode
!==
TorStatuses
.
EventNotification
)
{
logger
.
warn
(
"
Unexpected event status code:
"
,
aReply
.
statusCode
);
return
;
}
// TODO: do we need to handle multiple lines?
const
s
=
aReply
.
lineArray
[
0
];
const
idx
=
s
.
indexOf
(
"
"
);
if
(
idx
===
-
1
)
{
const
reply
=
replyObj
;
replyObj
=
{};
if
(
reply
.
statusCode
!==
TorStatuses
.
EventNotification
)
{
logger
.
error
(
"
Unexpected event status code:
"
,
reply
.
statusCode
);
return
;
}
const
eventType
=
s
.
substring
(
0
,
idx
);
const
msg
=
s
.
substring
(
idx
+
1
).
trim
();
if
(
eventType
===
"
STATUS_CLIENT
"
)
{
this
.
_processBootstrapStatus
(
msg
,
false
);
return
;
}
else
if
(
!
this
.
_eventsToMonitor
.
includes
(
eventType
))
{
logger
.
debug
(
`Dropping unlistened event
${
eventType
}
`
);
if
(
!
reply
.
lineArray
[
0
].
startsWith
(
`
${
type
}
`
))
{
logger
.
error
(
"
Wrong format for the first line:
"
,
reply
.
lineArray
[
0
]);
return
;
}
reply
.
lineArray
[
0
]
=
reply
.
lineArray
[
0
].
substring
(
type
.
length
+
1
);
callback
(
type
,
reply
.
lineArray
);
},
true
);
},
if
(
eventType
===
"
WARN
"
||
eventType
===
"
ERR
"
)
{
_processLog
(
type
,
lines
)
{
if
(
type
===
"
WARN
"
||
type
===
"
ERR
"
)
{
// Notify so that Copy Log can be enabled.
Services
.
obs
.
notifyObservers
(
null
,
TorTopics
.
HasWarnOrErr
);
}
const
now
=
new
Date
();
const
date
=
new
Date
();
const
maxEntries
=
Services
.
prefs
.
getIntPref
(
"
extensions.torlauncher.max_tor_log_entries
"
,
1000
...
...
@@ -384,8 +379,10 @@ export const TorMonitorService = {
if
(
maxEntries
>
0
&&
this
.
_torLog
.
length
>=
maxEntries
)
{
this
.
_torLog
.
splice
(
0
,
1
);
}
this
.
_torLog
.
push
({
date
:
now
,
type
:
eventType
,
msg
});
const
logString
=
`Tor
${
eventType
}
:
${
msg
}
`
;
const
msg
=
lines
.
join
(
"
\n
"
);
this
.
_torLog
.
push
({
date
,
type
,
msg
});
const
logString
=
`Tor
${
type
}
:
${
msg
}
`
;
logger
.
info
(
logString
);
},
...
...
This diff is collapsed.
Click to expand it.
toolkit/components/tor-launcher/TorParsers.sys.mjs
+
6
−
6
View file @
2d3871a1
...
...
@@ -181,12 +181,12 @@ export const TorParsers = Object.freeze({
return
aStr
;
}
const
escaped
=
aStr
.
replace
(
"
\\
"
,
"
\\\\
"
)
.
replace
(
'
"
'
,
'
\\
"
'
)
.
replace
(
"
\n
"
,
"
\\
n
"
)
.
replace
(
"
\r
"
,
"
\\
r
"
)
.
replace
(
"
\t
"
,
"
\\
t
"
)
.
replace
(
/
[^\x
20-
\x
7e
]
+/g
,
text
=>
{
.
replace
All
(
"
\\
"
,
"
\\\\
"
)
.
replace
All
(
'
"
'
,
'
\\
"
'
)
.
replace
All
(
"
\n
"
,
"
\\
n
"
)
.
replace
All
(
"
\r
"
,
"
\\
r
"
)
.
replace
All
(
"
\t
"
,
"
\\
t
"
)
.
replace
All
(
/
[^\x
20-
\x
7e
]
+/g
,
text
=>
{
const
encoder
=
new
TextEncoder
();
return
Array
.
from
(
encoder
.
encode
(
text
),
...
...
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
sign in
to comment