Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
Stunserver
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
Stunserver
Commits
d7a27efb
Commit
d7a27efb
authored
Feb 01, 2012
by
John Selbie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Final touches for version 1.1
parent
25b3d600
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
97 additions
and
27 deletions
+97
-27
common/fasthash.cpp
common/fasthash.cpp
+17
-0
common/fasthash.h
common/fasthash.h
+15
-6
server/tcpserver.cpp
server/tcpserver.cpp
+4
-11
stuncore/messagehandler.cpp
stuncore/messagehandler.cpp
+2
-2
stuncore/stunbuilder.cpp
stuncore/stunbuilder.cpp
+2
-1
stuncore/stunreader.cpp
stuncore/stunreader.cpp
+20
-5
stuncore/stuntypes.h
stuncore/stuntypes.h
+4
-0
testcode/testpolling.cpp
testcode/testpolling.cpp
+17
-2
testcode/testpolling.h
testcode/testpolling.h
+16
-0
No files found.
common/fasthash.cpp
View file @
d7a27efb
/*
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)
...
...
common/fasthash.h
View file @
d7a27efb
/*
* 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
...
...
server/tcpserver.cpp
View file @
d7a27efb
...
...
@@ -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
;
}
...
...
stuncore/messagehandler.cpp
View file @
d7a27efb
...
...
@@ -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
);
...
...
stuncore/stunbuilder.cpp
View file @
d7a27efb
...
...
@@ -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
)
...
...
stuncore/stunreader.cpp
View file @
d7a27efb
...
...
@@ -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
;
}
...
...
stuncore/stuntypes.h
View file @
d7a27efb
...
...
@@ -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
;
...
...
testcode/testpolling.cpp
View file @
d7a27efb
/*
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
));
...
...
testcode/testpolling.h
View file @
d7a27efb
/*
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment