Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maunium
synapse
Commits
872cf435
Unverified
Commit
872cf435
authored
6 years ago
by
Amber Brown
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #3303 from NotAFile/py3-memoryview
use memoryview in py3
parents
debff7ae
4b9d0cde
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
synapse/storage/keys.py
+11
-3
11 additions, 3 deletions
synapse/storage/keys.py
synapse/storage/signatures.py
+10
-2
10 additions, 2 deletions
synapse/storage/signatures.py
synapse/storage/transactions.py
+9
-1
9 additions, 1 deletion
synapse/storage/transactions.py
with
30 additions
and
6 deletions
synapse/storage/keys.py
+
11
−
3
View file @
872cf435
...
@@ -17,6 +17,7 @@ from ._base import SQLBaseStore
...
@@ -17,6 +17,7 @@ from ._base import SQLBaseStore
from
synapse.util.caches.descriptors
import
cachedInlineCallbacks
from
synapse.util.caches.descriptors
import
cachedInlineCallbacks
from
twisted.internet
import
defer
from
twisted.internet
import
defer
import
six
import
OpenSSL
import
OpenSSL
from
signedjson.key
import
decode_verify_key_bytes
from
signedjson.key
import
decode_verify_key_bytes
...
@@ -26,6 +27,13 @@ import logging
...
@@ -26,6 +27,13 @@ import logging
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
# py2 sqlite has buffer hardcoded as only binary type, so we must use it,
# despite being deprecated and removed in favor of memoryview
if
six
.
PY2
:
db_binary_type
=
buffer
else
:
db_binary_type
=
memoryview
class
KeyStore
(
SQLBaseStore
):
class
KeyStore
(
SQLBaseStore
):
"""
Persistence for signature verification keys and tls X.509 certificates
"""
Persistence for signature verification keys and tls X.509 certificates
...
@@ -72,7 +80,7 @@ class KeyStore(SQLBaseStore):
...
@@ -72,7 +80,7 @@ class KeyStore(SQLBaseStore):
values
=
{
values
=
{
"
from_server
"
:
from_server
,
"
from_server
"
:
from_server
,
"
ts_added_ms
"
:
time_now_ms
,
"
ts_added_ms
"
:
time_now_ms
,
"
tls_certificate
"
:
buffer
(
tls_certificate_bytes
),
"
tls_certificate
"
:
db_binary_type
(
tls_certificate_bytes
),
},
},
desc
=
"
store_server_certificate
"
,
desc
=
"
store_server_certificate
"
,
)
)
...
@@ -135,7 +143,7 @@ class KeyStore(SQLBaseStore):
...
@@ -135,7 +143,7 @@ class KeyStore(SQLBaseStore):
values
=
{
values
=
{
"
from_server
"
:
from_server
,
"
from_server
"
:
from_server
,
"
ts_added_ms
"
:
time_now_ms
,
"
ts_added_ms
"
:
time_now_ms
,
"
verify_key
"
:
buffer
(
verify_key
.
encode
()),
"
verify_key
"
:
db_binary_type
(
verify_key
.
encode
()),
},
},
)
)
txn
.
call_after
(
txn
.
call_after
(
...
@@ -172,7 +180,7 @@ class KeyStore(SQLBaseStore):
...
@@ -172,7 +180,7 @@ class KeyStore(SQLBaseStore):
"
from_server
"
:
from_server
,
"
from_server
"
:
from_server
,
"
ts_added_ms
"
:
ts_now_ms
,
"
ts_added_ms
"
:
ts_now_ms
,
"
ts_valid_until_ms
"
:
ts_expires_ms
,
"
ts_valid_until_ms
"
:
ts_expires_ms
,
"
key_json
"
:
buffer
(
key_json_bytes
),
"
key_json
"
:
db_binary_type
(
key_json_bytes
),
},
},
desc
=
"
store_server_keys_json
"
,
desc
=
"
store_server_keys_json
"
,
)
)
...
...
This diff is collapsed.
Click to expand it.
synapse/storage/signatures.py
+
10
−
2
View file @
872cf435
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
# limitations under the License.
# limitations under the License.
from
twisted.internet
import
defer
from
twisted.internet
import
defer
import
six
from
._base
import
SQLBaseStore
from
._base
import
SQLBaseStore
...
@@ -21,6 +22,13 @@ from unpaddedbase64 import encode_base64
...
@@ -21,6 +22,13 @@ from unpaddedbase64 import encode_base64
from
synapse.crypto.event_signing
import
compute_event_reference_hash
from
synapse.crypto.event_signing
import
compute_event_reference_hash
from
synapse.util.caches.descriptors
import
cached
,
cachedList
from
synapse.util.caches.descriptors
import
cached
,
cachedList
# py2 sqlite has buffer hardcoded as only binary type, so we must use it,
# despite being deprecated and removed in favor of memoryview
if
six
.
PY2
:
db_binary_type
=
buffer
else
:
db_binary_type
=
memoryview
class
SignatureWorkerStore
(
SQLBaseStore
):
class
SignatureWorkerStore
(
SQLBaseStore
):
@cached
()
@cached
()
...
@@ -56,7 +64,7 @@ class SignatureWorkerStore(SQLBaseStore):
...
@@ -56,7 +64,7 @@ class SignatureWorkerStore(SQLBaseStore):
for
e_id
,
h
in
hashes
.
items
()
for
e_id
,
h
in
hashes
.
items
()
}
}
defer
.
returnValue
(
hashes
.
items
())
defer
.
returnValue
(
list
(
hashes
.
items
())
)
def
_get_event_reference_hashes_txn
(
self
,
txn
,
event_id
):
def
_get_event_reference_hashes_txn
(
self
,
txn
,
event_id
):
"""
Get all the hashes for a given PDU.
"""
Get all the hashes for a given PDU.
...
@@ -91,7 +99,7 @@ class SignatureStore(SignatureWorkerStore):
...
@@ -91,7 +99,7 @@ class SignatureStore(SignatureWorkerStore):
vals
.
append
({
vals
.
append
({
"
event_id
"
:
event
.
event_id
,
"
event_id
"
:
event
.
event_id
,
"
algorithm
"
:
ref_alg
,
"
algorithm
"
:
ref_alg
,
"
hash
"
:
buffer
(
ref_hash_bytes
),
"
hash
"
:
db_binary_type
(
ref_hash_bytes
),
})
})
self
.
_simple_insert_many_txn
(
self
.
_simple_insert_many_txn
(
...
...
This diff is collapsed.
Click to expand it.
synapse/storage/transactions.py
+
9
−
1
View file @
872cf435
...
@@ -17,6 +17,7 @@ from ._base import SQLBaseStore
...
@@ -17,6 +17,7 @@ from ._base import SQLBaseStore
from
synapse.util.caches.descriptors
import
cached
from
synapse.util.caches.descriptors
import
cached
from
twisted.internet
import
defer
from
twisted.internet
import
defer
import
six
from
canonicaljson
import
encode_canonical_json
from
canonicaljson
import
encode_canonical_json
...
@@ -25,6 +26,13 @@ from collections import namedtuple
...
@@ -25,6 +26,13 @@ from collections import namedtuple
import
logging
import
logging
import
simplejson
as
json
import
simplejson
as
json
# py2 sqlite has buffer hardcoded as only binary type, so we must use it,
# despite being deprecated and removed in favor of memoryview
if
six
.
PY2
:
db_binary_type
=
buffer
else
:
db_binary_type
=
memoryview
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
@@ -110,7 +118,7 @@ class TransactionStore(SQLBaseStore):
...
@@ -110,7 +118,7 @@ class TransactionStore(SQLBaseStore):
"
transaction_id
"
:
transaction_id
,
"
transaction_id
"
:
transaction_id
,
"
origin
"
:
origin
,
"
origin
"
:
origin
,
"
response_code
"
:
code
,
"
response_code
"
:
code
,
"
response_json
"
:
buffer
(
encode_canonical_json
(
response_dict
)),
"
response_json
"
:
db_binary_type
(
encode_canonical_json
(
response_dict
)),
"
ts
"
:
self
.
_clock
.
time_msec
(),
"
ts
"
:
self
.
_clock
.
time_msec
(),
},
},
or_ignore
=
True
,
or_ignore
=
True
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment