sync process

This commit is contained in:
Kevin Jahns
2014-09-29 11:58:30 +02:00
parent 8fcd8f6809
commit c337f37665
40 changed files with 154 additions and 64 deletions

View File

@@ -19,7 +19,7 @@
}
PeerJsConnector = (function() {
function PeerJsConnector(engine, HB, execution_listener, yatta) {
var send_;
var send_, sync_every_collaborator;
this.engine = engine;
this.HB = HB;
this.execution_listener = execution_listener;
@@ -31,6 +31,21 @@
return _this.addConnection(conn);
};
})(this));
sync_every_collaborator = (function(_this) {
return function() {
var conn, conn_id, _ref, _results;
_ref = _this.connections;
_results = [];
for (conn_id in _ref) {
conn = _ref[conn_id];
_results.push(conn.send({
sync_state_vector: _this.HB.getOperationCounter()
}));
}
return _results;
};
})(this);
setInterval(sync_every_collaborator, 8000);
send_ = (function(_this) {
return function(o) {
var conn, conn_id, _ref, _results;
@@ -78,9 +93,11 @@
} else if (data.HB != null) {
initialized_me = true;
_this.engine.applyOpsCheckDouble(data.HB);
return conn.send({
conns: _this.getAllConnectionIds()
});
if (!data.initialized) {
return conn.send({
conns: _this.getAllConnectionIds()
});
}
} else if (data.op != null) {
return _this.engine.applyOp(data.op);
} else if (data.conns != null) {
@@ -91,10 +108,17 @@
_results.push(_this.connectToPeer(conn_id));
}
return _results;
} else if (data.sync_state_vector != null) {
console.log("turinae");
return conn.send({
HB: _this.yatta.getHistoryBuffer()._encode(data.sync_state_vector),
initialized: true
});
} else if (data.state_vector != null) {
if (!initialized_him) {
conn.send({
HB: _this.yatta.getHistoryBuffer()._encode(data.state_vector)
HB: _this.yatta.getHistoryBuffer()._encode(data.state_vector),
initialized: false
});
return initialized_him = true;
}

File diff suppressed because one or more lines are too long

View File

@@ -66,7 +66,9 @@
var o;
o = this.parseOperation(op_json);
this.HB.addToCounter(o);
if (!o.execute()) {
if (this.HB.getOperation(o) != null) {
} else if (!o.execute()) {
this.unprocessed_ops.push(o);
} else {
this.HB.addOperation(o);
@@ -83,7 +85,9 @@
_ref = this.unprocessed_ops;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
op = _ref[_i];
if (!op.execute()) {
if (this.HB.getOperation(op) != null) {
} else if (!op.execute()) {
unprocessed.push(op);
} else {
this.HB.addOperation(op);

File diff suppressed because one or more lines are too long