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
a864e40c
Commit
a864e40c
authored
Dec 09, 2018
by
John Selbie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove atomichelpers.cpp
parent
19d5cf47
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
56 additions
and
224 deletions
+56
-224
common/Makefile
common/Makefile
+1
-1
common/atomichelpers.cpp
common/atomichelpers.cpp
+0
-79
common/atomichelpers.h
common/atomichelpers.h
+0
-27
common/crc32.cpp
common/crc32.cpp
+1
-1
common/crc32.h
common/crc32.h
+1
-14
stuncore/stunbuilder.cpp
stuncore/stunbuilder.cpp
+26
-13
stuncore/stunbuilder.h
stuncore/stunbuilder.h
+4
-1
stuncore/stunreader.cpp
stuncore/stunreader.cpp
+1
-1
testcode/Makefile
testcode/Makefile
+1
-1
testcode/testatomichelpers.cpp
testcode/testatomichelpers.cpp
+0
-50
testcode/testatomichelpers.h
testcode/testatomichelpers.h
+0
-33
testcode/testbuilder.cpp
testcode/testbuilder.cpp
+20
-0
testcode/testbuilder.h
testcode/testbuilder.h
+1
-0
testcode/testcode.cpp
testcode/testcode.cpp
+0
-3
No files found.
common/Makefile
View file @
a864e40c
include
../common.inc
include
../common.inc
PROJECT_TARGET
:=
libcommon.a
PROJECT_TARGET
:=
libcommon.a
PROJECT_SRCS
:=
atomichelpers.cpp
cmdlineparser.cpp common.cpp condmutex.cpp crc32.cpp fasthash.cpp getconsolewidth.cpp getmillisecondcounter.cpp logger.cpp prettyprint.cpp stringhelper.cpp
PROJECT_SRCS
:=
cmdlineparser.cpp common.cpp condmutex.cpp crc32.cpp fasthash.cpp getconsolewidth.cpp getmillisecondcounter.cpp logger.cpp prettyprint.cpp stringhelper.cpp
PROJECT_OBJS
:=
$(
subst
.cpp,.o,
$(PROJECT_SRCS)
)
PROJECT_OBJS
:=
$(
subst
.cpp,.o,
$(PROJECT_SRCS)
)
INCLUDES
:=
$(BOOST_INCLUDE)
INCLUDES
:=
$(BOOST_INCLUDE)
PRECOMP_H_GCH
:=
commonincludes.hpp.gch
PRECOMP_H_GCH
:=
commonincludes.hpp.gch
...
...
common/atomichelpers.cpp
deleted
100644 → 0
View file @
19d5cf47
/*
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.hpp"
#include "atomichelpers.h"
#if defined(i386) || defined(__i386) || defined(__i386__)
#define ATOMICS_USE_XADD
#endif
#ifdef ATOMICS_USE_XADD
unsigned
int
xadd_4
(
volatile
void
*
pVal
,
unsigned
int
inc
)
{
unsigned
int
result
;
unsigned
int
*
pValInt
=
(
unsigned
int
*
)
pVal
;
asm
volatile
(
"lock; xaddl %%eax, %2;"
:
"=a"
(
result
)
:
"a"
(
inc
),
"m"
(
*
pValInt
)
:
"memory"
);
return
(
result
);
}
int
AtomicIncrement
(
int
*
pInt
)
{
COMPILE_TIME_ASSERT
(
sizeof
(
int
)
==
4
);
// InterlockedIncrement
unsigned
int
result
=
xadd_4
(
pInt
,
1
)
+
1
;
return
(
int
)
result
;
}
int
AtomicDecrement
(
int
*
pInt
)
{
// InterlockedDecrement
unsigned
int
result
=
xadd_4
(
pInt
,
-
1
)
-
1
;
return
(
int
)
result
;
}
#else
int
AtomicIncrement
(
int
*
pInt
)
{
COMPILE_TIME_ASSERT
(
sizeof
(
int
)
==
4
);
// InterlockedIncrement
return
__sync_add_and_fetch
(
pInt
,
1
);
}
int
AtomicDecrement
(
int
*
pInt
)
{
// InterlockedDecrement
return
__sync_sub_and_fetch
(
pInt
,
1
);
}
#endif
common/atomichelpers.h
deleted
100644 → 0
View file @
19d5cf47
/*
Copyright 2013 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 ATOMICHELPERS_H
#define ATOMICHELPERS_H
int
AtomicIncrement
(
int
*
pInt
);
int
AtomicDecrement
(
int
*
pInt
);
#endif
/* ATOMICHELPERS_H */
common/crc32.cpp
View file @
a864e40c
...
@@ -67,7 +67,7 @@ static const uint32_t crc_table[256] = {
...
@@ -67,7 +67,7 @@ static const uint32_t crc_table[256] = {
#define DO8(buf) DO4(buf); DO4(buf);
#define DO8(buf) DO4(buf); DO4(buf);
/* ========================================================================= */
/* ========================================================================= */
uint32_t
crc32
(
uint32_t
crc
,
uint8_t
*
buf
,
size_t
len
)
uint32_t
crc32
(
uint32_t
crc
,
const
uint8_t
*
buf
,
size_t
len
)
{
{
if
(
buf
==
nullptr
)
return
0L
;
if
(
buf
==
nullptr
)
return
0L
;
crc
=
crc
^
0xffffffffL
;
crc
=
crc
^
0xffffffffL
;
...
...
common/crc32.h
View file @
a864e40c
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: crc32.h
* Author: jselbie
*
* Created on September 3, 2018, 11:22 PM
*/
#ifndef CRC32_H
#ifndef CRC32_H
#define CRC32_H
#define CRC32_H
uint32_t
crc32
(
uint32_t
crc
,
uint8_t
*
buf
,
size_t
len
);
uint32_t
crc32
(
uint32_t
crc
,
const
uint8_t
*
buf
,
size_t
len
);
#endif
/* CRC32_H */
#endif
/* CRC32_H */
...
...
stuncore/stunbuilder.cpp
View file @
a864e40c
...
@@ -17,9 +17,13 @@
...
@@ -17,9 +17,13 @@
#include "commonincludes.hpp"
#include "commonincludes.hpp"
#include <sstream>
#include <atomic>
#include "stringhelper.h"
#include "stringhelper.h"
#include "atomichelpers.h"
#include "oshelper.h"
#include "stunbuilder.h"
#include "stunbuilder.h"
...
@@ -32,12 +36,10 @@
...
@@ -32,12 +36,10 @@
#endif
#endif
#include "crc32.h"
#include "crc32.h"
#include "stunauth.h"
#include "stunauth.h"
st
atic
int
g_sequence_number
=
0xaaaaaaaa
;
st
d
::
atomic
<
int
>
g_sequence_number
;
CStunMessageBuilder
::
CStunMessageBuilder
()
:
CStunMessageBuilder
::
CStunMessageBuilder
()
:
...
@@ -91,6 +93,25 @@ HRESULT CStunMessageBuilder::AddTransactionId(const StunTransactionId& transid)
...
@@ -91,6 +93,25 @@ HRESULT CStunMessageBuilder::AddTransactionId(const StunTransactionId& transid)
return
_stream
.
Write
(
transid
.
id
,
sizeof
(
transid
.
id
));
return
_stream
.
Write
(
transid
.
id
,
sizeof
(
transid
.
id
));
}
}
uint32_t
CStunMessageBuilder
::
GetEntropy
()
{
uint32_t
entropy
=
0
;
std
::
ostringstream
ss
;
ss
<<
g_sequence_number
.
fetch_add
(
1
);
ss
<<
'.'
;
ss
<<
getpid
();
ss
<<
'.'
;
ss
<<
reinterpret_cast
<
uintptr_t
>
(
this
);
ss
<<
'.'
;
ss
<<
time
(
nullptr
);
ss
<<
'.'
;
ss
<<
GetMillisecondCounter
();
std
::
string
str
;
str
=
ss
.
str
();
entropy
=
crc32
(
0
,
(
const
uint8_t
*
)(
str
.
c_str
()),
str
.
size
());
return
entropy
;
}
HRESULT
CStunMessageBuilder
::
AddRandomTransactionId
(
StunTransactionId
*
pTransId
)
HRESULT
CStunMessageBuilder
::
AddRandomTransactionId
(
StunTransactionId
*
pTransId
)
{
{
StunTransactionId
transid
;
StunTransactionId
transid
;
...
@@ -98,11 +119,9 @@ HRESULT CStunMessageBuilder::AddRandomTransactionId(StunTransactionId* pTransId)
...
@@ -98,11 +119,9 @@ HRESULT CStunMessageBuilder::AddRandomTransactionId(StunTransactionId* pTransId)
uint32_t
entropy
=
0
;
uint32_t
entropy
=
0
;
// on x86, the rdtsc instruction is about as good as it gets for a random sequence number
// on x86, the rdtsc instruction is about as good as it gets for a random sequence number
// on linux, there's /dev/urandom
// on linux, there's /dev/urandom
#ifdef _WIN32
#ifdef _WIN32
// on windows, there's lots of simple stuff we can get at to give us a random number
// on windows, there's lots of simple stuff we can get at to give us a random number
// the rdtsc instruction is about as good as it gets
// the rdtsc instruction is about as good as it gets
...
@@ -121,21 +140,15 @@ HRESULT CStunMessageBuilder::AddRandomTransactionId(StunTransactionId* pTransId)
...
@@ -121,21 +140,15 @@ HRESULT CStunMessageBuilder::AddRandomTransactionId(StunTransactionId* pTransId)
}
}
}
}
if
(
entropy
==
0
)
if
(
entropy
==
0
)
{
{
entropy
^=
getpid
();
entropy
=
GetEntropy
();
entropy
^=
reinterpret_cast
<
uintptr_t
>
(
this
);
entropy
^=
time
(
nullptr
);
entropy
^=
AtomicIncrement
(
&
g_sequence_number
);
}
}
#endif
#endif
srand
(
entropy
);
srand
(
entropy
);
// the first four bytes of the transaction id is always the magic cookie
// the first four bytes of the transaction id is always the magic cookie
// followed by 12 bytes of the real transaction id
// followed by 12 bytes of the real transaction id
memcpy
(
transid
.
id
,
&
stun_cookie_nbo
,
sizeof
(
stun_cookie_nbo
));
memcpy
(
transid
.
id
,
&
stun_cookie_nbo
,
sizeof
(
stun_cookie_nbo
));
...
...
stuncore/stunbuilder.h
View file @
a864e40c
...
@@ -38,7 +38,8 @@ private:
...
@@ -38,7 +38,8 @@ private:
HRESULT
AddMappedAddressImpl
(
uint16_t
attribute
,
const
CSocketAddress
&
addr
);
HRESULT
AddMappedAddressImpl
(
uint16_t
attribute
,
const
CSocketAddress
&
addr
);
HRESULT
AddMessageIntegrityImpl
(
uint8_t
*
key
,
size_t
keysize
);
HRESULT
AddMessageIntegrityImpl
(
uint8_t
*
key
,
size_t
keysize
);
uint32_t
GetEntropy
();
public:
public:
CStunMessageBuilder
();
CStunMessageBuilder
();
...
@@ -83,6 +84,8 @@ public:
...
@@ -83,6 +84,8 @@ public:
HRESULT
GetResult
(
CRefCountedBuffer
*
pspBuffer
);
HRESULT
GetResult
(
CRefCountedBuffer
*
pspBuffer
);
CDataStream
&
GetStream
();
CDataStream
&
GetStream
();
friend
class
CTestBuilder
;
};
};
#endif
#endif
stuncore/stunreader.cpp
View file @
a864e40c
...
@@ -55,7 +55,7 @@ void CStunMessageReader::Reset()
...
@@ -55,7 +55,7 @@ void CStunMessageReader::Reset()
_indexMessageIntegrity
=
-
1
;
_indexMessageIntegrity
=
-
1
;
_countAttributes
=
0
;
_countAttributes
=
0
;
memset
(
&
_transactionid
,
'\0'
,
sizeof
(
_transactionid
))
;
_transactionid
=
{}
;
_msgTypeNormalized
=
0xffff
;
_msgTypeNormalized
=
0xffff
;
_msgClass
=
StunMsgClassInvalidMessageClass
;
_msgClass
=
StunMsgClassInvalidMessageClass
;
_msgLength
=
0
;
_msgLength
=
0
;
...
...
testcode/Makefile
View file @
a864e40c
include
../common.inc
include
../common.inc
PROJECT_TARGET
:=
stuntestcode
PROJECT_TARGET
:=
stuntestcode
PROJECT_OBJS
:=
benchmark.o test
atomichelpers.o test
builder.o testclientlogic.o testcmdline.o testcrc32.o testcode.o testdatastream.o testfasthash.o testintegrity.o testmessagehandler.o testpolling.o testratelimiter.o testreader.o testrecvfromex.o
PROJECT_OBJS
:=
benchmark.o testbuilder.o testclientlogic.o testcmdline.o testcrc32.o testcode.o testdatastream.o testfasthash.o testintegrity.o testmessagehandler.o testpolling.o testratelimiter.o testreader.o testrecvfromex.o
INCLUDES
:=
$(BOOST_INCLUDE)
$(OPENSSL_INCLUDE)
-I
../common
-I
../stuncore
-I
../networkutils
INCLUDES
:=
$(BOOST_INCLUDE)
$(OPENSSL_INCLUDE)
-I
../common
-I
../stuncore
-I
../networkutils
LIB_PATH
:=
-L
../networkutils
-L
../stuncore
-L
../common
LIB_PATH
:=
-L
../networkutils
-L
../stuncore
-L
../common
...
...
testcode/testatomichelpers.cpp
deleted
100644 → 0
View file @
19d5cf47
/*
Copyright 2013 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.hpp"
#include "testatomichelpers.h"
#include "atomichelpers.h"
HRESULT
CTestAtomicHelpers
::
Run
()
{
HRESULT
hr
=
S_OK
;
int
value
=
-
2000
;
int
nextexpected
=
-
2000
;
int
result
=
0
;
while
(
value
<
2000
)
{
nextexpected
++
;
result
=
AtomicIncrement
(
&
value
);
ChkIf
(
result
!=
nextexpected
,
E_UNEXPECTED
);
ChkIf
(
result
!=
value
,
E_UNEXPECTED
);
}
value
=
2000
;
nextexpected
=
2000
;
while
(
value
>
-
2000
)
{
nextexpected
--
;
result
=
AtomicDecrement
(
&
value
);
ChkIf
(
result
!=
nextexpected
,
E_UNEXPECTED
);
ChkIf
(
result
!=
value
,
E_UNEXPECTED
);
}
Cleanup:
return
hr
;
}
\ No newline at end of file
testcode/testatomichelpers.h
deleted
100644 → 0
View file @
19d5cf47
/*
Copyright 2013 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 TESTATOMICHELPERS_H
#define TESTATOMICHELPERS_H
#include "unittest.h"
class
CTestAtomicHelpers
:
public
IUnitTest
{
public:
virtual
HRESULT
Run
();
UT_DECLARE_TEST_NAME
(
"CTestAtomicHelpers"
);
};
#endif
/* TESTATOMICHELPERS_H */
testcode/testbuilder.cpp
View file @
a864e40c
...
@@ -27,6 +27,7 @@ HRESULT CTestBuilder::Run()
...
@@ -27,6 +27,7 @@ HRESULT CTestBuilder::Run()
HRESULT
hr
=
S_OK
;
HRESULT
hr
=
S_OK
;
Chk
(
Test1
())
Chk
(
Test1
())
Chk
(
Test2
());
Chk
(
Test2
());
Chk
(
TestEntropy
());
Cleanup:
Cleanup:
return
hr
;
return
hr
;
}
}
...
@@ -138,4 +139,23 @@ Cleanup:
...
@@ -138,4 +139,23 @@ Cleanup:
return
hr
;
return
hr
;
}
}
HRESULT
CTestBuilder
::
TestEntropy
()
{
CStunMessageBuilder
builder
;
HRESULT
hr
=
S_OK
;
uint32_t
prev
=
0
;
for
(
int
x
=
0
;
x
<
15
;
x
++
)
{
uint32_t
e
=
builder
.
GetEntropy
();
ChkIfA
(
e
==
0
,
E_FAIL
);
ChkIfA
(
e
==
prev
,
E_FAIL
);
prev
=
e
;
}
Cleanup:
return
hr
;
}
testcode/testbuilder.h
View file @
a864e40c
...
@@ -26,6 +26,7 @@ class CTestBuilder : public IUnitTest
...
@@ -26,6 +26,7 @@ class CTestBuilder : public IUnitTest
public:
public:
HRESULT
Test1
();
HRESULT
Test1
();
HRESULT
Test2
();
HRESULT
Test2
();
HRESULT
TestEntropy
();
virtual
HRESULT
Run
();
virtual
HRESULT
Run
();
...
...
testcode/testcode.cpp
View file @
a864e40c
...
@@ -33,7 +33,6 @@
...
@@ -33,7 +33,6 @@
#include "prettyprint.h"
#include "prettyprint.h"
#include "polling.h"
#include "polling.h"
#include "testpolling.h"
#include "testpolling.h"
#include "testatomichelpers.h"
#include "testratelimiter.h"
#include "testratelimiter.h"
void
ReaderFuzzTest
()
void
ReaderFuzzTest
()
...
@@ -85,7 +84,6 @@ void RunUnitTests()
...
@@ -85,7 +84,6 @@ void RunUnitTests()
std
::
shared_ptr
<
CTestRecvFromExIPV6
>
spTestRecvFromEx6
(
new
CTestRecvFromExIPV6
);
std
::
shared_ptr
<
CTestRecvFromExIPV6
>
spTestRecvFromEx6
(
new
CTestRecvFromExIPV6
);
std
::
shared_ptr
<
CTestFastHash
>
spTestFastHash
(
new
CTestFastHash
);
std
::
shared_ptr
<
CTestFastHash
>
spTestFastHash
(
new
CTestFastHash
);
std
::
shared_ptr
<
CTestPolling
>
spTestPolling
(
new
CTestPolling
);
std
::
shared_ptr
<
CTestPolling
>
spTestPolling
(
new
CTestPolling
);
std
::
shared_ptr
<
CTestAtomicHelpers
>
spTestAtomicHelpers
(
new
CTestAtomicHelpers
);
std
::
shared_ptr
<
CTestRateLimiter
>
spTestRateLimiter
(
new
CTestRateLimiter
);
std
::
shared_ptr
<
CTestRateLimiter
>
spTestRateLimiter
(
new
CTestRateLimiter
);
std
::
shared_ptr
<
CTestCRC32
>
spTestCRC32
(
new
CTestCRC32
);
std
::
shared_ptr
<
CTestCRC32
>
spTestCRC32
(
new
CTestCRC32
);
...
@@ -100,7 +98,6 @@ void RunUnitTests()
...
@@ -100,7 +98,6 @@ void RunUnitTests()
vecTests
.
push_back
(
spTestRecvFromEx6
);
vecTests
.
push_back
(
spTestRecvFromEx6
);
vecTests
.
push_back
(
spTestFastHash
);
vecTests
.
push_back
(
spTestFastHash
);
vecTests
.
push_back
(
spTestPolling
);
vecTests
.
push_back
(
spTestPolling
);
vecTests
.
push_back
(
spTestAtomicHelpers
);
vecTests
.
push_back
(
spTestRateLimiter
);
vecTests
.
push_back
(
spTestRateLimiter
);
vecTests
.
push_back
(
spTestCRC32
);
vecTests
.
push_back
(
spTestCRC32
);
...
...
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