Skip to content

Commit

Permalink
Merge pull request #14 from kyuhojeong/timestamp
Browse files Browse the repository at this point in the history
Timestamp Log Detailing
  • Loading branch information
pstjuste committed Jan 9, 2014
2 parents 3ad1057 + 1c61ebd commit 76870af
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 19 deletions.
2 changes: 2 additions & 0 deletions build/ipop-tincan.gyp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@
'ipop-project/ipop-tincan/src/xmppnetwork.h',
'ipop-project/ipop-tincan/src/controlleraccess.cc',
'ipop-project/ipop-tincan/src/controlleraccess.h',
'ipop-project/ipop-tincan/src/tincan_utils.h',
'ipop-project/ipop-tincan/src/tincan_utils.cc',
'xmpp/jingleinfotask.cc',
'xmpp/jingleinfotask.h',
],
Expand Down
3 changes: 2 additions & 1 deletion src/controlleraccess.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "talk/base/json.h"

#include "controlleraccess.h"
#include "tincan_utils.h"

namespace tincan {

Expand Down Expand Up @@ -100,7 +101,7 @@ void ControllerAccess::SendToPeer(int overlay_id, const std::string& uid,
json["type"] = type;
std::string msg = json.toStyledString();
SendTo(msg.c_str(), msg.size(), remote_addr_);
LOG_F(INFO) << uid << " " << data;
LOG_TS(INFO) << uid << " " << data;
}

void ControllerAccess::SendState(const std::string& uid,
Expand Down
3 changes: 2 additions & 1 deletion src/tincan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@

#include "talk/base/ssladapter.h"

#include "tincanconnectionmanager.h"
#include "controlleraccess.h"
#include "tincanconnectionmanager.h"
#include "tincan_utils.h"
#include "xmppnetwork.h"

#define SEGMENT_SIZE 3
Expand Down
52 changes: 52 additions & 0 deletions src/tincan_utils.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* ipop-tincan
* Copyright 2013, University of Florida
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#if defined(LINUX)
#include "tincan_utils.h"

namespace tincan {

std::ostream & operator << (std::ostream & out, const CurrentTime & ct) {

struct timeval time;
struct tm * ttm = NULL;
gettimeofday(&time, NULL);
ttm = localtime(&time.tv_sec);

out << "[" << std::setfill('0') << std::setw(2) << ttm->tm_mon + 1
<< "/" << std::setfill('0') << std::setw(2) << ttm->tm_mday
<< " " << std::setfill('0') << std::setw(2) << ttm->tm_hour
<< ":" << std::setfill('0') << std::setw(2) << ttm->tm_min
<< ":" << std::setfill('0') << std::setw(2) << ttm->tm_sec
<< "." << std::setfill('0') << std::setw(6) << time.tv_usec
<< "] ";

return out;
}

} //namespace tincan
#endif //if defined(LINUX)
52 changes: 52 additions & 0 deletions src/tincan_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* ipop-tincan
* Copyright 2013, University of Florida
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef TINCAN_UTILS_H_
#define TINCAN_UTILS_H_
#pragma once

#if defined(LINUX)
#define LOG_TS(sev) LOG(sev) << tincan::CurrentTime() << __FUNCTION__ << ": "
#else
#define LOG_TS(sev) LOG_F(sev) << __FUNCTION__ << ": "
#endif //if defined(LINUX)

#if defined(LINUX)
#include <iomanip>
#include <iostream>
#include <sys/time.h>

namespace tincan {

class CurrentTime {
friend std::ostream & operator << (std::ostream &, const CurrentTime &);
};

} //namespace tincan

#endif //if defined(LINUX)
#endif //ifndef TINCAN_UTILS_H_
17 changes: 9 additions & 8 deletions src/tincanconnectionmanager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@

#include "talk/base/logging.h"

#include "tincan_utils.h"
#include "tincanconnectionmanager.h"


namespace tincan {

static const char kIpv4[] = "172.31.0.100";
Expand Down Expand Up @@ -136,11 +138,11 @@ void TinCanConnectionManager::OnRWChangeState(
std::string status = "unknown";
if (transport->readable() && transport->writable()) {
status = "online";
LOG_F(INFO) << "ONLINE " << uid << " " << talk_base::Time();
LOG_TS(INFO) << "ONLINE " << uid << " " << talk_base::Time();
}
else if (transport->was_writable()) {
status = "offline";
LOG_F(INFO) << "OFFLINE " << uid << " " << talk_base::Time();
LOG_TS(INFO) << "OFFLINE " << uid << " " << talk_base::Time();
}
// callback message sent to local controller for connection status
signal_sender_->SendToPeer(kLocalControllerId, uid, status, kConStat);
Expand Down Expand Up @@ -212,7 +214,6 @@ void TinCanConnectionManager::HandlePacket(talk_base::AsyncPacketSocket* socket,
forward_socket_->SendTo(data, len, forward_addr_,talk_base::DSCP_DEFAULT);
}
else if (short_uid_map_[dest]->writable()) {
LOG_F(INFO) << "found in uid map and send packet to channel\n";
int component = cricket::ICE_CANDIDATE_COMPONENT_DEFAULT;
cricket::TransportChannelImpl* channel =
short_uid_map_[dest]->GetChannel(component);
Expand Down Expand Up @@ -241,7 +242,7 @@ bool TinCanConnectionManager::SetRelay(
// TODO - TCP relaying needs more testing
//peer_state->port_allocator->AddRelay(relay_config_tcp);
}
LOG_F(INFO) << "TURN " << turn_addr.ToString();
LOG_TS(INFO) << "TURN " << turn_addr.ToString();
return true;
}

Expand Down Expand Up @@ -286,11 +287,11 @@ bool TinCanConnectionManager::CreateTransport(
const std::string& turn_user, const std::string& turn_pass,
const bool sec_enabled) {
if (uid_map_.find(uid) != uid_map_.end() || tincan_id_ == uid) {
LOG_F(INFO) << "EXISTS " << uid;
LOG_TS(INFO) << "EXISTS " << uid;
return false;
}

LOG_F(INFO) << uid << " " << talk_base::Time();
LOG_TS(INFO) << uid << " " << talk_base::Time();
talk_base::SocketAddress stun_addr;
stun_addr.FromString(stun_server);
PeerStatePtr peer_state(new talk_base::RefCountedObject<PeerState>);
Expand Down Expand Up @@ -390,7 +391,7 @@ bool TinCanConnectionManager::DestroyTransport(const std::string& uid) {
uid_map_[uid]->port_allocator.release();
uid_map_.erase(uid);
short_uid_map_.erase(uid.substr(0, kShortLen * 2));
LOG_F(INFO) << "DESTROYED " << uid;
LOG_TS(INFO) << "DESTROYED " << uid;
return true;
}

Expand All @@ -413,7 +414,7 @@ void TinCanConnectionManager::HandlePeer(const std::string& uid,
else {
signal_sender_->SendToPeer(kLocalControllerId, uid, data, kConReq);
}
LOG_F(INFO) << uid << " " << data;
LOG_TS(INFO) << uid << " " << data;
}

int TinCanConnectionManager::DoPacketSend(const char* buf, size_t len) {
Expand Down
15 changes: 8 additions & 7 deletions src/xmppnetwork.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "talk/xmpp/jid.h"
#include "talk/xmpp/constants.h"

#include "tincan_utils.h"
#include "xmppnetwork.h"

namespace tincan {
Expand Down Expand Up @@ -146,7 +147,7 @@ bool XmppNetwork::Connect() {
pump_->client()->SignalStateChange.connect(this,
&XmppNetwork::OnStateChange);
pump_->DoLogin(xcs_, xmpp_socket_.get(), 0);
LOG_F(INFO) << "XMPP CONNECTING";
LOG_TS(INFO) << "XMPP CONNECTING";
return true;
}

Expand All @@ -172,23 +173,23 @@ void XmppNetwork::OnSignOn() {
tincan_task_->Start();
main_thread_->Clear(this);
main_thread_->PostDelayed(kInterval, this, 0, 0);
LOG_F(INFO) << "XMPP ONLINE " << pump_->client()->jid().Str();
LOG_TS(INFO) << "XMPP ONLINE " << pump_->client()->jid().Str();
}

void XmppNetwork::OnStateChange(buzz::XmppEngine::State state) {
switch (state) {
case buzz::XmppEngine::STATE_START:
LOG_F(INFO) << "START";
LOG_TS(INFO) << "START";
break;
case buzz::XmppEngine::STATE_OPENING:
LOG_F(INFO) << "OPENING";
LOG_TS(INFO) << "OPENING";
break;
case buzz::XmppEngine::STATE_OPEN:
LOG_F(INFO) << "OPEN";
LOG_TS(INFO) << "OPEN";
OnSignOn();
break;
case buzz::XmppEngine::STATE_CLOSED:
LOG_F(INFO) << "CLOSED";
LOG_TS(INFO) << "CLOSED";
OnCloseEvent(0);
break;
}
Expand Down Expand Up @@ -217,7 +218,7 @@ void XmppNetwork::OnCloseEvent(int error) {
presence_out_.release();
tincan_task_.release();
pump_.release();
LOG_F(INFO) << "XMPP CLOSE " << error;
LOG_TS(INFO) << "XMPP CLOSE " << error;
}

void XmppNetwork::OnMessage(talk_base::Message* msg) {
Expand Down
5 changes: 3 additions & 2 deletions src/xmppnetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "talk/base/logging.h"

#include "peersignalsender.h"
#include "tincan_utils.h"

namespace tincan {

Expand All @@ -55,7 +56,7 @@ class TinCanTask

virtual void set_xmpp_id(const std::string& uid_key,
const std::string& uid) {
LOG_F(INFO) << "SET_XMPP_ID " << uid;
LOG_TS(INFO) << "SET_XMPP_ID " << uid;
xmpp_id_map_[uid_key] = uid;
}

Expand Down Expand Up @@ -101,7 +102,7 @@ class XmppNetwork
}

void OnLogging(const char* data, int len) {
LOG_F(LS_VERBOSE) << std::string(data, len);
LOG_TS(LS_VERBOSE) << std::string(data, len);
}

// Inherited from MessageHandler
Expand Down

0 comments on commit 76870af

Please sign in to comment.