mirror of
https://github.com/octoleo/syncthing.git
synced 2025-02-02 11:58:28 +00:00
Compression as a user option (fixes #446)
This commit is contained in:
parent
933b61f99f
commit
67a3fb8bf2
File diff suppressed because one or more lines are too long
@ -288,6 +288,7 @@ func restPostConfig(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|||||||
nm := newCfg.NodeMap()
|
nm := newCfg.NodeMap()
|
||||||
for k := range om {
|
for k := range om {
|
||||||
if _, ok := nm[k]; !ok {
|
if _, ok := nm[k]; !ok {
|
||||||
|
// A node was removed and another added
|
||||||
configInSync = false
|
configInSync = false
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -654,7 +654,7 @@ next:
|
|||||||
wr = &limitedWriter{conn, rateBucket}
|
wr = &limitedWriter{conn, rateBucket}
|
||||||
}
|
}
|
||||||
name := fmt.Sprintf("%s-%s", conn.LocalAddr(), conn.RemoteAddr())
|
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)
|
l.Infof("Established secure connection to %s at %s", remoteID, name)
|
||||||
if debugNet {
|
if debugNet {
|
||||||
|
@ -93,9 +93,10 @@ func (r *RepositoryConfiguration) NodeIDs() []protocol.NodeID {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type NodeConfiguration struct {
|
type NodeConfiguration struct {
|
||||||
NodeID protocol.NodeID `xml:"id,attr"`
|
NodeID protocol.NodeID `xml:"id,attr"`
|
||||||
Name string `xml:"name,attr,omitempty"`
|
Name string `xml:"name,attr,omitempty"`
|
||||||
Addresses []string `xml:"address,omitempty"`
|
Addresses []string `xml:"address,omitempty"`
|
||||||
|
Compression bool `xml:"compression,attr"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type OptionsConfiguration struct {
|
type OptionsConfiguration struct {
|
||||||
|
@ -372,7 +372,7 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
|
|||||||
};
|
};
|
||||||
|
|
||||||
$scope.addNode = function () {
|
$scope.addNode = function () {
|
||||||
$scope.currentNode = {AddressesStr: 'dynamic'};
|
$scope.currentNode = {AddressesStr: 'dynamic', Compression: true};
|
||||||
$scope.editingExisting = false;
|
$scope.editingExisting = false;
|
||||||
$scope.editingSelf = false;
|
$scope.editingSelf = false;
|
||||||
$scope.nodeEditor.$setPristine();
|
$scope.nodeEditor.$setPristine();
|
||||||
|
@ -313,6 +313,11 @@
|
|||||||
<th><span class="glyphicon glyphicon-comment"></span> <span translate>Synchronization</span></th>
|
<th><span class="glyphicon glyphicon-comment"></span> <span translate>Synchronization</span></th>
|
||||||
<td class="text-right">{{connections[nodeCfg.NodeID].Completion | alwaysNumber}}%</td>
|
<td class="text-right">{{connections[nodeCfg.NodeID].Completion | alwaysNumber}}%</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th><span class="glyphicon glyphicon-compressed"></span> <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>
|
<tr>
|
||||||
<th><span class="glyphicon glyphicon-cloud-download"></span> <span translate>Download Rate</span></th>
|
<th><span class="glyphicon glyphicon-cloud-download"></span> <span translate>Download Rate</span></th>
|
||||||
<td class="text-right">{{connections[nodeCfg.NodeID].inbps | metric}}bps ({{connections[nodeCfg.NodeID].InBytesTotal | binary}}B)</td>
|
<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>
|
<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>
|
<p translate class="help-block">Enter comma separated "ip:port" addresses or "dynamic" to perform automatic discovery of the address.</p>
|
||||||
</div>
|
</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>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
|
@ -101,6 +101,7 @@
|
|||||||
"Upgrade To {%version%}": "Upgrade To {{version}}",
|
"Upgrade To {%version%}": "Upgrade To {{version}}",
|
||||||
"Upload Rate": "Upload Rate",
|
"Upload Rate": "Upload Rate",
|
||||||
"Usage": "Usage",
|
"Usage": "Usage",
|
||||||
|
"Use Compression": "Use Compression",
|
||||||
"Use HTTPS for GUI": "Use HTTPS for GUI",
|
"Use HTTPS for GUI": "Use HTTPS for GUI",
|
||||||
"Version": "Version",
|
"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.",
|
"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.",
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
<node id="JMFJCXB-GZDE4BN-OCJE3VF-65GYZNU-AIVJRET-3J6HMRQ-AUQIGJO-FKNHMQU"></node>
|
<node id="JMFJCXB-GZDE4BN-OCJE3VF-65GYZNU-AIVJRET-3J6HMRQ-AUQIGJO-FKNHMQU"></node>
|
||||||
<versioning></versioning>
|
<versioning></versioning>
|
||||||
</repository>
|
</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>
|
<address>127.0.0.1:22001</address>
|
||||||
</node>
|
</node>
|
||||||
<node id="JMFJCXB-GZDE4BN-OCJE3VF-65GYZNU-AIVJRET-3J6HMRQ-AUQIGJO-FKNHMQU" name="s2">
|
<node id="JMFJCXB-GZDE4BN-OCJE3VF-65GYZNU-AIVJRET-3J6HMRQ-AUQIGJO-FKNHMQU" name="s2">
|
||||||
|
@ -18,10 +18,10 @@
|
|||||||
<versioning></versioning>
|
<versioning></versioning>
|
||||||
<syncorder></syncorder>
|
<syncorder></syncorder>
|
||||||
</repository>
|
</repository>
|
||||||
<node id="I6KAH7666SLLL5PFXSOAUFJCDZYAOMLEKCP2GB3BV5RQST3PSROA" name="s1">
|
<node id="I6KAH7666SLLL5PFXSOAUFJCDZYAOMLEKCP2GB3BV5RQST3PSROA" name="s1" compression="true">
|
||||||
<address>127.0.0.1:22001</address>
|
<address>127.0.0.1:22001</address>
|
||||||
</node>
|
</node>
|
||||||
<node id="JMFJCXBGZDE4BOCJE3VF65GYZNAIVJRET3J6HMRAUQIGJOFKNHMQ" name="s2">
|
<node id="JMFJCXBGZDE4BOCJE3VF65GYZNAIVJRET3J6HMRAUQIGJOFKNHMQ" name="s2" compression="true">
|
||||||
<address>127.0.0.1:22002</address>
|
<address>127.0.0.1:22002</address>
|
||||||
</node>
|
</node>
|
||||||
<node id="373HSRPQLPNLIJYKZVQFP4PKZ6R2ZE6K3YD442UJHBGBQGWWXAHA" name="s3">
|
<node id="373HSRPQLPNLIJYKZVQFP4PKZ6R2ZE6K3YD442UJHBGBQGWWXAHA" name="s3">
|
||||||
|
@ -18,8 +18,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
BlockSize = 128 * 1024
|
BlockSize = 128 * 1024
|
||||||
MinCompressedSize = 128 // message must be this big to enable compression
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -101,6 +100,8 @@ type rawConnection struct {
|
|||||||
closed chan struct{}
|
closed chan struct{}
|
||||||
once sync.Once
|
once sync.Once
|
||||||
|
|
||||||
|
compressionThreshold int // compress messages larger than this many bytes
|
||||||
|
|
||||||
rdbuf0 []byte // used & reused by readMessage
|
rdbuf0 []byte // used & reused by readMessage
|
||||||
rdbuf1 []byte // used & reused by readMessage
|
rdbuf1 []byte // used & reused by readMessage
|
||||||
}
|
}
|
||||||
@ -124,20 +125,25 @@ const (
|
|||||||
pingIdleTime = 60 * time.Second
|
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}
|
cr := &countingReader{Reader: reader}
|
||||||
cw := &countingWriter{Writer: writer}
|
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{
|
c := rawConnection{
|
||||||
id: nodeID,
|
id: nodeID,
|
||||||
name: name,
|
name: name,
|
||||||
receiver: nativeModel{receiver},
|
receiver: nativeModel{receiver},
|
||||||
state: stateInitial,
|
state: stateInitial,
|
||||||
cr: cr,
|
cr: cr,
|
||||||
cw: cw,
|
cw: cw,
|
||||||
outbox: make(chan hdrMsg),
|
outbox: make(chan hdrMsg),
|
||||||
nextID: make(chan int),
|
nextID: make(chan int),
|
||||||
closed: make(chan struct{}),
|
closed: make(chan struct{}),
|
||||||
|
compressionThreshold: compThres,
|
||||||
}
|
}
|
||||||
|
|
||||||
go c.readerLoop()
|
go c.readerLoop()
|
||||||
@ -470,7 +476,7 @@ func (c *rawConnection) writerLoop() {
|
|||||||
// Uncompressed message in uncBuf
|
// Uncompressed message in uncBuf
|
||||||
uncBuf = hm.msg.AppendXDR(uncBuf[:0])
|
uncBuf = hm.msg.AppendXDR(uncBuf[:0])
|
||||||
|
|
||||||
if len(uncBuf) >= MinCompressedSize {
|
if len(uncBuf) >= c.compressionThreshold {
|
||||||
// Use compression for large messages
|
// Use compression for large messages
|
||||||
hm.hdr.compression = true
|
hm.hdr.compression = true
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user