[tor-bugs] #28940 [Obfuscation/Pluggable transport]: Add support for LOG to goptlib

Tor Bug Tracker & Wiki blackhole at torproject.org
Fri Feb 8 03:06:28 UTC 2019


#28940: Add support for LOG to goptlib
---------------------------------------------+-----------------------------
 Reporter:  dcf                              |          Owner:  dcf
     Type:  enhancement                      |         Status:
                                             |  needs_review
 Priority:  Medium                           |      Milestone:
Component:  Obfuscation/Pluggable transport  |        Version:
 Severity:  Normal                           |     Resolution:
 Keywords:  goptlib                          |  Actual Points:
Parent ID:                                   |         Points:  0.3
 Reviewer:                                   |        Sponsor:  Sponsor19
---------------------------------------------+-----------------------------
Changes (by dcf):

 * status:  needs_revision => needs_review


Comment:

 Replying to [comment:8 ahf]:
 > Let's do this as an extension and keep `goptlib` for the low level
 details. `goptlibext` could be the name.

 I definitely want a basic `Log` function in goptlib itself. A higher-level
 interface, using `log.Logger` for example, is a good candidate for a
 separate library that builds on goptlib, I agree.

 Here's an implementation of `Log` along the lines of what I was thinking.
 The [attachment:0001-Bug-28940-add-support-for-LOG.patch full patch]
 includes more documentation and tests.
 {{{
 // Severity levels for the Log function.
 const (
         LogLevelError   = "error"
         LogLevelWarning = "warning"
         LogLevelNotice  = "notice"
         LogLevelInfo    = "info"
         LogLevelDebug   = "debug"
 )

 // Encode a string according to the CString rules of section 2.1.1 in
 // control-spec.txt.
 //
 // We additionally need to ensure that whatever we return passes
 argIsSafe,
 // because strings encoded by this function are printed verbatim by Log.
 func encodeCString(s string) string {
         result := bytes.NewBuffer([]byte{})
         result.WriteByte('"')
         for _, c := range []byte(s) {
                 if c == 32 || c == 33 || (35 <= c && c <= 91) || (93 <= c
 && c <= 126) {
                         result.WriteByte(c)
                 } else {
                         fmt.Fprintf(result, "\\%03o", c)
                 }
         }
         result.WriteByte('"')
         return result.String()
 }

 // Emit a LOG message with the given severity (one of LogLevelError,
 // LogLevelWarning, LogLevelNotice, LogLevelInfo, or LogLevelDebug).
 func Log(severity, message string) {
         // "<Message> contains the log message which can be a String or
 CString..."
         // encodeCString always makes the string safe to emit; i.e., it
         // satisfies argIsSafe.
         line("LOG", "SEVERITY="+encodeCString(severity),
 "MESSAGE="+encodeCString(message))
 }
 }}}

--
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/28940#comment:9>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online


More information about the tor-bugs mailing list