Browse Source

Compression as a user option (fixes #446)

Jakob Borg 11 years ago
parent
commit
67a3fb8bf2

File diff suppressed because it is too large
+ 0 - 0
auto/gui.files.go


+ 1 - 0
cmd/syncthing/gui.go

@@ -288,6 +288,7 @@ func restPostConfig(m *model.Model, w http.ResponseWriter, r *http.Request) {
 			nm := newCfg.NodeMap()
 			for k := range om {
 				if _, ok := nm[k]; !ok {
+					// A node was removed and another added
 					configInSync = false
 					break
 				}

+ 1 - 1
cmd/syncthing/main.go

@@ -654,7 +654,7 @@ next:
 					wr = &limitedWriter{conn, rateBucket}
 				}
 				name := fmt.Sprintf("%s-%s", conn.LocalAddr(), conn.RemoteAddr())
-				protoConn := protocol.NewConnection(remoteID, conn, wr, m, name)
+				protoConn := protocol.NewConnection(remoteID, conn, wr, m, name, nodeCfg.Compression)
 
 				l.Infof("Established secure connection to %s at %s", remoteID, name)
 				if debugNet {

+ 4 - 3
config/config.go

@@ -93,9 +93,10 @@ func (r *RepositoryConfiguration) NodeIDs() []protocol.NodeID {
 }
 
 type NodeConfiguration struct {
-	NodeID    protocol.NodeID `xml:"id,attr"`
-	Name      string          `xml:"name,attr,omitempty"`
-	Addresses []string        `xml:"address,omitempty"`
+	NodeID      protocol.NodeID `xml:"id,attr"`
+	Name        string          `xml:"name,attr,omitempty"`
+	Addresses   []string        `xml:"address,omitempty"`
+	Compression bool            `xml:"compression,attr"`
 }
 
 type OptionsConfiguration struct {

+ 1 - 1
gui/app.js

@@ -372,7 +372,7 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
     };
 
     $scope.addNode = function () {
-        $scope.currentNode = {AddressesStr: 'dynamic'};
+        $scope.currentNode = {AddressesStr: 'dynamic', Compression: true};
         $scope.editingExisting = false;
         $scope.editingSelf = false;
         $scope.nodeEditor.$setPristine();

+ 12 - 0
gui/index.html

@@ -313,6 +313,11 @@
                         <th><span class="glyphicon glyphicon-comment"></span>&emsp;<span translate>Synchronization</span></th>
                         <td class="text-right">{{connections[nodeCfg.NodeID].Completion | alwaysNumber}}%</td>
                       </tr>
+                      <tr>
+                        <th><span class="glyphicon glyphicon-compressed"></span>&emsp;<span translate>Use Compression</span></th>
+                        <td translate ng-if="nodeCfg.Compression" class="text-right">Yes</td>
+                        <td translate ng-if="!nodeCfg.Compression" class="text-right">No</td>
+                      </tr>
                       <tr>
                         <th><span class="glyphicon glyphicon-cloud-download"></span>&emsp;<span translate>Download Rate</span></th>
                         <td class="text-right">{{connections[nodeCfg.NodeID].inbps | metric}}bps ({{connections[nodeCfg.NodeID].InBytesTotal | binary}}B)</td>
@@ -428,6 +433,13 @@
               <input placeholder="dynamic" ng-disabled="currentNode.NodeID == myID" id="addresses" class="form-control" type="text" ng-model="currentNode.AddressesStr"></input>
               <p translate class="help-block">Enter comma separated "ip:port" addresses or "dynamic" to perform automatic discovery of the address.</p>
             </div>
+            <div class="form-group">
+              <div class="checkbox">
+                <label>
+                  <input type="checkbox" ng-model="currentNode.Compression"> <span translate>Use Compression</span>
+                </label>
+              </div>
+            </div>
           </form>
         </div>
         <div class="modal-footer">

+ 1 - 0
gui/lang-en.json

@@ -101,6 +101,7 @@
    "Upgrade To {%version%}": "Upgrade To {{version}}",
    "Upload Rate": "Upload Rate",
    "Usage": "Usage",
+   "Use Compression": "Use Compression",
    "Use HTTPS for GUI": "Use HTTPS for GUI",
    "Version": "Version",
    "When adding a new node, keep in mind that this node must be added on the other side too.": "When adding a new node, keep in mind that this node must be added on the other side too.",

+ 1 - 1
integration/h1/config.xml

@@ -10,7 +10,7 @@
         <node id="JMFJCXB-GZDE4BN-OCJE3VF-65GYZNU-AIVJRET-3J6HMRQ-AUQIGJO-FKNHMQU"></node>
         <versioning></versioning>
     </repository>
-    <node id="I6KAH76-66SLLLB-5PFXSOA-UFJCDZC-YAOMLEK-CP2GB32-BV5RQST-3PSROAU" name="s1">
+    <node id="I6KAH76-66SLLLB-5PFXSOA-UFJCDZC-YAOMLEK-CP2GB32-BV5RQST-3PSROAU" name="s1" compression="true">
         <address>127.0.0.1:22001</address>
     </node>
     <node id="JMFJCXB-GZDE4BN-OCJE3VF-65GYZNU-AIVJRET-3J6HMRQ-AUQIGJO-FKNHMQU" name="s2">

+ 2 - 2
integration/h2/config.xml

@@ -18,10 +18,10 @@
         <versioning></versioning>
         <syncorder></syncorder>
     </repository>
-    <node id="I6KAH7666SLLL5PFXSOAUFJCDZYAOMLEKCP2GB3BV5RQST3PSROA" name="s1">
+    <node id="I6KAH7666SLLL5PFXSOAUFJCDZYAOMLEKCP2GB3BV5RQST3PSROA" name="s1" compression="true">
         <address>127.0.0.1:22001</address>
     </node>
-    <node id="JMFJCXBGZDE4BOCJE3VF65GYZNAIVJRET3J6HMRAUQIGJOFKNHMQ" name="s2">
+    <node id="JMFJCXBGZDE4BOCJE3VF65GYZNAIVJRET3J6HMRAUQIGJOFKNHMQ" name="s2" compression="true">
         <address>127.0.0.1:22002</address>
     </node>
     <node id="373HSRPQLPNLIJYKZVQFP4PKZ6R2ZE6K3YD442UJHBGBQGWWXAHA" name="s3">

+ 19 - 13
protocol/protocol.go

@@ -18,8 +18,7 @@ import (
 )
 
 const (
-	BlockSize         = 128 * 1024
-	MinCompressedSize = 128 // message must be this big to enable compression
+	BlockSize = 128 * 1024
 )
 
 const (
@@ -101,6 +100,8 @@ type rawConnection struct {
 	closed chan struct{}
 	once   sync.Once
 
+	compressionThreshold int // compress messages larger than this many bytes
+
 	rdbuf0 []byte // used & reused by readMessage
 	rdbuf1 []byte // used & reused by readMessage
 }
@@ -124,20 +125,25 @@ const (
 	pingIdleTime = 60 * time.Second
 )
 
-func NewConnection(nodeID NodeID, reader io.Reader, writer io.Writer, receiver Model, name string) Connection {
+func NewConnection(nodeID NodeID, reader io.Reader, writer io.Writer, receiver Model, name string, compress bool) Connection {
 	cr := &countingReader{Reader: reader}
 	cw := &countingWriter{Writer: writer}
 
+	compThres := 1<<32 - 1 // compression disabled
+	if compress {
+		compThres = 128 // compress messages that are 128 bytes long or larger
+	}
 	c := rawConnection{
-		id:       nodeID,
-		name:     name,
-		receiver: nativeModel{receiver},
-		state:    stateInitial,
-		cr:       cr,
-		cw:       cw,
-		outbox:   make(chan hdrMsg),
-		nextID:   make(chan int),
-		closed:   make(chan struct{}),
+		id:                   nodeID,
+		name:                 name,
+		receiver:             nativeModel{receiver},
+		state:                stateInitial,
+		cr:                   cr,
+		cw:                   cw,
+		outbox:               make(chan hdrMsg),
+		nextID:               make(chan int),
+		closed:               make(chan struct{}),
+		compressionThreshold: compThres,
 	}
 
 	go c.readerLoop()
@@ -470,7 +476,7 @@ func (c *rawConnection) writerLoop() {
 				// Uncompressed message in uncBuf
 				uncBuf = hm.msg.AppendXDR(uncBuf[:0])
 
-				if len(uncBuf) >= MinCompressedSize {
+				if len(uncBuf) >= c.compressionThreshold {
 					// Use compression for large messages
 					hm.hdr.compression = true
 

Some files were not shown because too many files changed in this diff