通过日志文件分析Peercast的HANDSHAKE过程

[DBUG] ShoutCast client

void Servent::handshakeHTTP(HTTP &http, bool isHTTP)
{
 LOG_DEBUG("ShoutCast client");
 handshakeICY(Channel::SRC_SHOUTCAST,isHTTP);
}

void Servent::handshakeICY(Channel::SRC_TYPE type, bool isHTTP)
{
 servMgr->checkFirewall();
 //Channel ID用IP地址和速率来编码以避免重复
 info.id = chanMgr->broadcastID;
 info.id.encode(NULL,info.name.cstr(),loginMount,info.bitrate);
 LOG_DEBUG("Incoming source: %s : %s",info.name.cstr(),ChanInfo::getTypeStr(info.contentType));
 c = chanMgr->createChannel(info,loginMount); //创建频道
}

[DBUG] ICY icy-name:Sonic's radio
[DBUG] ICY icy-genre:Pop
[DBUG] ICY icy-url:http://www.sonic.com
[DBUG] ICY icy-irc:#shoutcast
[DBUG] ICY icy-icq:0
[DBUG] ICY icy-aim:N/A
[DBUG] ICY icy-pub:1
[DBUG] ICY icy-br:48

bool Servent::handshakeStream(ChanInfo &chanInfo)
{

 HTTP http(*sock);

if (chanInfo.contentType != ChanInfo::T_MP3)
   addMetadata=false;

  if (addMetadata && (outputProtocol == ChanInfo::SP_HTTP))  // winamp mp3 metadata check
  {

   sock->writeLine(ICY_OK);

   sock->writeLineF("%s %s",HTTP_HS_SERVER,PCX_AGENT);
   sock->writeLineF("icy-name:%s",chanInfo.name.cstr());
   sock->writeLineF("icy-br:%d",chanInfo.bitrate);
   sock->writeLineF("icy-genre:%s",chanInfo.genre.cstr());
   sock->writeLineF("icy-url:%s",chanInfo.url.cstr());
   sock->writeLineF("icy-metaint:%d",chanMgr->icyMetaInterval);
   sock->writeLineF("%s %s",PCX_HS_CHANNELID,idStr);

   sock->writeLineF("%s %s",HTTP_HS_CONTENT,MIME_MP3);

  }

}

在开始前我们需要一个有效的IP地址

[DBUG] Checking firewall..

void ServMgr::checkFirewall()
{
   Servent::handshakeOutgoingPCP(atom,sock->host,remoteID,agent,true);
}

[DBUG] PCP outgoing waiting for OLEH..
[DBUG] Got new ip: 218.249.186.209:0
[DBUG] Firewall is set to ON
[DBUG] PCP Outgoing handshake complete.

void Servent::handshakeOutgoingPCP(AtomStream &atom, Host &rhost, GnuID &rid, String &agent, bool isTrusted)
{
   LOG_DEBUG("PCP outgoing waiting for OLEH..");

   LOG_DEBUG("Got new ip: %s",ipstr);
   servMgr->serverHost.ip = thisHost.ip;
  
   LOG_DEBUG("PCP Outgoing handshake complete.");
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值