Commit d7a27efb authored by John Selbie's avatar John Selbie

Final touches for version 1.1

parent 25b3d600
/*
Copyright 2011 John Selbie
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "commonincludes.h"
#define IS_DIVISIBLE_BY(x, y) ((x % y)==0)
......
/*
* File: main.cpp
* Author: jselbie
*
* Created on December 3, 2011, 11:18 PM
*/
/*
Copyright 2011 John Selbie
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef FASTHASH_H
#define FASTHASH_H
......
......@@ -189,7 +189,7 @@ HRESULT CTCPStunThread::CreateListenSockets()
ChkA(_socketListenArray[r].TCPInit(_tsaListen.set[r].addr, (SocketRole)r, true));
_socketTable[r] = _socketListenArray[r].GetSocketHandle();
ChkA(_socketListenArray[r].SetNonBlocking(true));
ret = listen(_socketTable[r], 128); // todo - figure out the right value to pass to listen
ret = listen(_socketTable[r], 128); // 128 - large backlog.
ChkIfA(ret == -1, ERRNOHR);
_countSocks++;
}
......@@ -281,9 +281,6 @@ HRESULT CTCPStunThread::Init(const TransportAddressSet& tsaListen, const Transpo
// add read end of pipe to epoll so we can get notified of when a signal to exit has occurred
ChkA(_spPolling->Add(_pipe[0], EPOLL_PIPE_EVENT_SET));
// todo - get "max connections" from an init param
ret = _hashConnections1.InitTable(_maxConnections, 0);
ChkIfA(ret == -1, E_FAIL);
......@@ -868,8 +865,6 @@ HRESULT CTCPServer::Initialize(const CStunServerConfig& config)
tsaListen = tsaHandler;
_threads[0] = new CTCPStunThread();
// todo - max connections needs to be a config param!
// todo - create auth
ChkA(_threads[0]->Init(tsaListen, tsaHandler, _spAuth, config.nMaxConnections));
}
else
......@@ -884,9 +879,8 @@ HRESULT CTCPServer::Initialize(const CStunServerConfig& config)
_threads[threadindex] = new CTCPStunThread();
// todo - max connections needs to be a config param!
// todo - create auth
Chk(_threads[threadindex]->Init(tsaListen, tsaHandler, NULL, config.nMaxConnections));
Chk(_threads[threadindex]->Init(tsaListen, tsaHandler, _spAuth, config.nMaxConnections));
}
}
}
......@@ -930,9 +924,8 @@ Cleanup:
HRESULT CTCPServer::Stop()
{
// for now shutdown and stop are equivalent
// for now shutdown and stop are equivalent (something about the notification "pipe" thing would need to get reset to restart the thread
// we don't really support restarting a server anyway
// todo - clean this up
Shutdown();
return S_OK;
}
......
......@@ -326,7 +326,7 @@ HRESULT CStunRequestHandler::ProcessBindingRequest()
// MAPPED-ADDRESS
// SOURCE-ADDRESS (RESPONSE-ORIGIN)
// CHANGED-ADDRESS (OTHER-ADDRESS)
// XOR-MAPPED-ADDRESS
// XOR-MAPPED-ADDRESS (XOR-MAPPED_ADDRESS-OPTIONAL)
builder.AddMappedAddress(_pMsgIn->addrRemote);
......@@ -340,7 +340,7 @@ HRESULT CStunRequestHandler::ProcessBindingRequest()
builder.AddOtherAddress(addrOther); // pass true to send back CHANGED-ADDRESS, otherwise, pass false to send back OTHER-ADDRESS
}
// even if this is a legacy client request, we can send back XOR-MAPPED-ADDRESS since it's an optional-understanding attribute
// send back the XOR-MAPPED-ADDRESS (encoded as an optional message for legacy clients)
builder.AddXorMappedAddress(_pMsgIn->addrRemote);
......
......@@ -301,10 +301,11 @@ Cleanup:
HRESULT CStunMessageBuilder::AddXorMappedAddress(const CSocketAddress& addr)
{
CSocketAddress addrxor(addr);
uint16_t attributeID = _fLegacyMode ? STUN_ATTRIBUTE_XORMAPPEDADDRESS_OPTIONAL : STUN_ATTRIBUTE_XORMAPPEDADDRESS;
addrxor.ApplyStunXorMap(_transactionid);
return AddMappedAddressImpl(STUN_ATTRIBUTE_XORMAPPEDADDRESS, addrxor);
return AddMappedAddressImpl(attributeID, addrxor);
}
HRESULT CStunMessageBuilder::AddMappedAddress(const CSocketAddress& addr)
......
......@@ -484,19 +484,34 @@ HRESULT CStunMessageReader::GetOtherAddress(CSocketAddress* pAddr)
HRESULT CStunMessageReader::GetXorMappedAddress(CSocketAddress* pAddr)
{
HRESULT hr = S_OK;
Chk(GetAddressHelper(STUN_ATTRIBUTE_XORMAPPEDADDRESS, pAddr));
pAddr->ApplyStunXorMap(_transactionid);
hr = GetAddressHelper(STUN_ATTRIBUTE_XORMAPPEDADDRESS, pAddr);
if (FAILED(hr))
{
// this is the vovida compat address attribute
hr = GetAddressHelper(STUN_ATTRIBUTE_XORMAPPEDADDRESS_OPTIONAL, pAddr);
}
if (SUCCEEDED(hr))
{
pAddr->ApplyStunXorMap(_transactionid);
}
Cleanup:
return hr;
}
HRESULT CStunMessageReader::GetResponseOriginAddress(CSocketAddress* pAddr)
{
HRESULT hr = S_OK;
Chk(GetAddressHelper(STUN_ATTRIBUTE_RESPONSE_ORIGIN, pAddr));
Cleanup:
hr = GetAddressHelper(STUN_ATTRIBUTE_RESPONSE_ORIGIN, pAddr);
if (FAILED(hr))
{
// look for the legacy address attribute that a legacy (RFC 3489) server would send
hr = GetAddressHelper(STUN_ATTRIBUTE_SOURCEADDRESS, pAddr);
}
return hr;
}
......
......@@ -53,6 +53,10 @@ const uint16_t STUN_ATTRIBUTE_NONCE = 0x0015;
const uint16_t STUN_ATTRIBUTE_XORMAPPEDADDRESS = 0x0020;
// This attribute is sent by the server to legacy clients
// 0x8020 is is not defined in any RFC, but is the value that Vovida server uses
const uint16_t STUN_ATTRIBUTE_XORMAPPEDADDRESS_OPTIONAL = 0x8020;
const uint16_t STUN_ATTRIBUTE_SOFTWARE = 0x8022;
const uint16_t STUN_ATTRIBUTE_ALTERNATESERVER = 0x8023;
const uint16_t STUN_ATTRIBUTE_PADDING = 0x8026;
......
/*
Copyright 2011 John Selbie
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "commonincludes.h"
#include "unittest.h"
......@@ -355,8 +371,7 @@ Cleanup:
HRESULT CTestPolling::Test3()
{
HRESULT hr = S_OK;
HRESULT hrResult;
PollEvent event;
const size_t c_maxSockets = 10;
ChkA(TestInit(c_maxSockets, 0));
......
/*
Copyright 2011 John Selbie
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef TEST_POLLING_H
#define TEST_POLLING_H
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment