Browse Source

mconnect, crypt: cleanup logging, use verbose debug where possible

bboozzoo/pairing-fixes
Maciek Borzecki 8 years ago
parent
commit
bc9c87e4bf
6 changed files with 20 additions and 19 deletions
  1. +2
    -2
      src/crypt/mconn-crypt.c
  2. +1
    -1
      src/mconnect/device.vala
  3. +5
    -5
      src/mconnect/devicechannel.vala
  4. +7
    -6
      src/mconnect/devicemanager.vala
  5. +4
    -4
      src/mconnect/discovery.vala
  6. +1
    -1
      src/mconnect/packet.vala

+ 2
- 2
src/crypt/mconn-crypt.c View File

@ -129,7 +129,7 @@ GByteArray * mconn_crypt_decrypt(MconnCrypt *self, GBytes *data, GError **err)
g_assert(IS_MCONN_CRYPT(self));
g_assert(self->priv->key);
g_debug("decrypt: %zu bytes of data", g_bytes_get_size(data));
/* g_debug("decrypt: %zu bytes of data", g_bytes_get_size(data)); */
g_assert_cmpint(g_bytes_get_size(data), ==, RSA_size(self->priv->key));
@ -143,7 +143,7 @@ GByteArray * mconn_crypt_decrypt(MconnCrypt *self, GBytes *data, GError **err)
(unsigned char *)out_data->data,
self->priv->key,
MCONN_CRYPT_RSA_PADDING);
g_debug("decrypted size: %d", dec_size);
/* g_debug("decrypted size: %d", dec_size); */
g_assert(dec_size != -1);
g_byte_array_set_size(out_data, dec_size);


+ 1
- 1
src/mconnect/device.vala View File

@ -266,7 +266,7 @@ class Device : Object {
}
private void packet_received(Packet pkt) {
debug("got packet");
vdebug("got packet");
if (pkt.pkt_type == Packet.PAIR) {
// pairing
handle_pair_packet(pkt);


+ 5
- 5
src/mconnect/devicechannel.vala View File

@ -191,7 +191,7 @@ class DeviceChannel : Object {
return false;
}
debug("received line: %s", data);
vdebug("received line: %s", data);
Packet pkt = Packet.new_from_data(data);
if (pkt == null) {
@ -244,13 +244,13 @@ class DeviceChannel : Object {
if (failed == true)
return;
debug("node data: %s", node.get_string());
vdebug("node data: %s", node.get_string());
// encrypted data is base64 encoded
uchar[] data = Base64.decode(node.get_string());
var dbytes = new Bytes.take(data);
try {
ByteArray decrypted = this._crypt.decrypt(dbytes);
debug("data length: %zu", decrypted.data.length);
vdebug("data length: %zu", decrypted.data.length);
msgbytes.append(decrypted.data);
} catch (Error e) {
warning("decryption failed: %s", e.message);
@ -258,11 +258,11 @@ class DeviceChannel : Object {
}
});
// data should be complete now
debug("total length of packet data: %zu", msgbytes.len);
vdebug("total length of packet data: %zu", msgbytes.len);
// make sure there is \0 at the end
msgbytes.append({'\0'});
string decrypted_data = ((string)msgbytes.data).dup();
debug("decrypted data: %s", decrypted_data);
vdebug("decrypted data: %s", decrypted_data);
Packet dec_pkt = Packet.new_from_data(decrypted_data);
if (dec_pkt == null) {


+ 7
- 6
src/mconnect/devicemanager.vala View File

@ -42,7 +42,7 @@ class DeviceManager : GLib.Object
private string get_cache_file() {
var cache_file = Path.build_filename(Core.get_cache_dir(),
DEVICES_CACHE_FILE);
debug("cache file: %s", cache_file);
vdebug("cache file: %s", cache_file);
// make sure that cache dir exists
DirUtils.create_with_parents(Core.get_cache_dir(),
@ -55,10 +55,10 @@ class DeviceManager : GLib.Object
* Load known devices from cache and attempt pairing.
*/
public void load_cache() {
debug("try loading devices from device cache");
var cache_file = get_cache_file();
debug("try loading devices from device cache %s", cache_file);
var kf = new KeyFile();
try {
kf.load_from_file(cache_file, KeyFileFlags.NONE);
@ -113,7 +113,7 @@ class DeviceManager : GLib.Object
public void handle_new_device(Device new_dev) {
var is_new = false;
string unique = new_dev.to_unique_string();
debug("device key: %s", unique);
vdebug("device key: %s", unique);
if (this.devices.has_key(unique) == false) {
debug("adding new device with key: %s", unique);
@ -129,7 +129,7 @@ class DeviceManager : GLib.Object
// update device information
dev.update_from_device(new_dev);
info("allowed? %s", dev.allowed.to_string());
debug("allowed? %s", dev.allowed.to_string());
// check if device is whitelisted in configuration
if (!dev.allowed && device_allowed_in_config(dev)) {
dev.allowed = true;
@ -142,7 +142,8 @@ class DeviceManager : GLib.Object
// device is allowed
activate_device(dev);
} else {
message("skipping device %s activation, device not allowed", dev.to_string());
warning("skipping device %s activation, device not allowed",
dev.to_string());
}
// notify everyone that a new device appeared


+ 4
- 4
src/mconnect/discovery.vala View File

@ -60,7 +60,7 @@ class Discovery : GLib.Object
}
private void incomingPacket() {
debug("incoming packet");
vdebug("incoming packet");
uint8 buffer[4096];
SocketAddress sa;
@ -69,14 +69,14 @@ class Discovery : GLib.Object
try {
ssize_t read = this.socket.receive_from(out sa, buffer);
isa = (InetSocketAddress)sa;
debug("got %zd bytes from: %s:%u", read,
vdebug("got %zd bytes from: %s:%u", read,
isa.address.to_string(), isa.port);
} catch (Error e) {
message("failed to receive packet: %s", e.message);
warning("failed to receive packet: %s", e.message);
return;
}
debug("message data: %s", (string)buffer);
vdebug("message data: %s", (string)buffer);
this.parsePacketFromHost((string) buffer, isa.address);
}


+ 1
- 1
src/mconnect/packet.vala View File

@ -67,7 +67,7 @@ class Packet : GLib.Object {
int64 id = root_obj.get_int_member("id");
Json.Object body = root_obj.get_object_member("body");
debug("packet type: %s", type);
vdebug("packet type: %s", type);
return new Packet(type, body, id);
} catch (Error e) {


Loading…
Cancel
Save