Skip to content

Commit d4095a9

Browse files
committed
go-tlsdialer: initial repository setup
To disable SSL by default we want to transfer OpenSslDialer and any other ssl logic to the new go-tlsdialer repository. go-tlsdialer serves as an interlayer between go-tarantool and go-openssl. All ssl logic from go-tarantool is moved to the go-tlsdialer. go-tlsdialer still uses tarantool connection, but also types and methods from go-openssl. This way we are removing the direct go-openssl dependency from go-tarantool, without creating a tarantool dependency in go-openssl. Moved all ssl code from go-tarantool, some test helpers. Added `README.md`, ci workflow. Part of tarantool/go-tarantool#301
1 parent 02359d7 commit d4095a9

22 files changed

+1964
-0
lines changed

.github/workflows/check.yml

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Run checks
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
luacheck:
9+
runs-on: ubuntu-latest
10+
if: |
11+
github.event_name == 'push' ||
12+
github.event_name == 'pull_request' &&
13+
github.event.pull_request.head.repo.full_name != github.repository
14+
steps:
15+
- uses: actions/checkout@master
16+
17+
- name: Setup Tarantool
18+
uses: tarantool/setup-tarantool@v2
19+
with:
20+
tarantool-version: '2.8'
21+
22+
- name: Setup tt
23+
run: |
24+
curl -L https://tarantool.io/release/2/installer.sh | sudo bash
25+
sudo apt install -y tt
26+
tt version
27+
28+
- name: Setup luacheck
29+
run: tt rocks install luacheck 0.25.0
30+
31+
- name: Run luacheck
32+
run: ./.rocks/bin/luacheck .
33+
34+
golangci-lint:
35+
runs-on: ubuntu-latest
36+
if: |
37+
github.event_name == 'push' ||
38+
github.event_name == 'pull_request' &&
39+
github.event.pull_request.head.repo.full_name != github.repository
40+
steps:
41+
- uses: actions/setup-go@v2
42+
43+
- uses: actions/checkout@v2
44+
45+
- name: golangci-lint
46+
uses: golangci/golangci-lint-action@v3
47+
continue-on-error: true
48+
with:
49+
# The first run is for GitHub Actions error format.
50+
args: --config=.golangci.yaml
51+
52+
- name: golangci-lint
53+
uses: golangci/golangci-lint-action@v3
54+
with:
55+
# The second run is for human-readable error format with a file name
56+
# and a line number.
57+
args: --out-${NO_FUTURE}format colored-line-number --config=.golangci.yaml
58+
59+
codespell:
60+
runs-on: ubuntu-latest
61+
if: |
62+
github.event_name == 'push' ||
63+
github.event_name == 'pull_request' &&
64+
github.event.pull_request.head.repo.full_name != github.repository
65+
steps:
66+
- uses: actions/checkout@master
67+
68+
- name: Install codespell
69+
run: pip3 install codespell
70+
71+
- name: Run codespell
72+
run: codespell

.github/workflows/testing.yml

+229
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
name: testing
2+
3+
on:
4+
push:
5+
pull_request:
6+
pull_request_target:
7+
types: [labeled]
8+
workflow_dispatch:
9+
10+
jobs:
11+
run-tests-ee:
12+
# Does not run on pull requests from forks and on forks by default.
13+
# Tests from forks will run only when the pull request is labeled with
14+
# `full-ci`. To avoid security problems, the label must be reset manually
15+
# for every run.
16+
#
17+
# We need to use `pull_request_target` because it has access to base
18+
# repository secrets unlike `pull_request`.
19+
if: |
20+
github.repository == 'tarantool/go-tlsdialer' &&
21+
(github.event_name == 'push' ||
22+
(github.event_name == 'pull_request_target' &&
23+
github.event.pull_request.head.repo.full_name != github.repository &&
24+
github.event.label.name == 'full-ci')) ||
25+
github.event_name == 'workflow_dispatch'
26+
27+
runs-on: ubuntu-latest
28+
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
sdk-path:
33+
- 'release/linux/x86_64/1.10/'
34+
sdk-version:
35+
- 'sdk-1.10.15-0-r598'
36+
coveralls: [ false ]
37+
fuzzing: [ false ]
38+
ssl: [ false ]
39+
include:
40+
- sdk-path: 'release/linux/x86_64/2.10/'
41+
sdk-version: 'sdk-gc64-2.10.8-0-r598.linux.x86_64'
42+
coveralls: false
43+
ssl: true
44+
- sdk-path: 'release/linux/x86_64/2.11/'
45+
sdk-version: 'sdk-gc64-2.11.1-0-r598.linux.x86_64'
46+
coveralls: true
47+
ssl: true
48+
49+
steps:
50+
- name: Clone the connector
51+
# `ref` as merge request is needed for pull_request_target because this
52+
# target runs in the context of the base commit of the pull request.
53+
uses: actions/checkout@v3
54+
if: github.event_name == 'pull_request_target'
55+
with:
56+
ref: refs/pull/${{ github.event.pull_request.number }}/merge
57+
58+
- name: Clone the connector
59+
if: github.event_name != 'pull_request_target'
60+
uses: actions/checkout@v3
61+
62+
- name: Setup Tarantool ${{ matrix.sdk-version }}
63+
run: |
64+
ARCHIVE_NAME=tarantool-enterprise-${{ matrix.sdk-version }}.tar.gz
65+
curl -O -L https://${{ secrets.SDK_DOWNLOAD_TOKEN }}@download.tarantool.io/enterprise/${{ matrix.sdk-path }}${ARCHIVE_NAME}
66+
tar -xzf ${ARCHIVE_NAME}
67+
rm -f ${ARCHIVE_NAME}
68+
69+
- name: Setup golang for the connector and tests
70+
uses: actions/setup-go@v3
71+
with:
72+
go-version: 1.13
73+
74+
- name: Run regression tests
75+
run: go test -v -shuffle=on -coverprofile=module-coverage.txt -coverpkg=./... ./...
76+
env:
77+
TEST_TNT_SSL: ${{matrix.ssl}}
78+
79+
- name: Collect coverage files
80+
shell: bash
81+
run: echo "COVERAGES=$(find . -type f -name 'module-coverage.txt' | tr -s '\n' ',' | sed 's/,$//')" >> $GITHUB_ENV
82+
- name: Upload coverage to Codecov
83+
uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0
84+
with:
85+
files: '${{ env.COVERAGES }}'
86+
env_vars: OS=${{ matrix.os }}, GO=${{ matrix.go }}
87+
88+
testing_mac_os:
89+
# We want to run on external PRs, but not on our own internal
90+
# PRs as they'll be run by the push to the branch.
91+
#
92+
# The main trick is described here:
93+
# https://github.com/Dart-Code/Dart-Code/pull/2375
94+
if: (github.event_name == 'push') ||
95+
(github.event_name == 'pull_request' &&
96+
github.event.pull_request.head.repo.full_name != github.repository) ||
97+
(github.event_name == 'workflow_dispatch')
98+
99+
strategy:
100+
fail-fast: false
101+
matrix:
102+
golang:
103+
- 1.13
104+
runs-on:
105+
- macos-11
106+
- macos-12
107+
tarantool:
108+
- brew
109+
- 1.10.15
110+
111+
env:
112+
# Make sense only for non-brew jobs.
113+
#
114+
# Set as absolute paths to avoid any possible confusion
115+
# after changing a current directory.
116+
T_VERSION: ${{ matrix.tarantool }}
117+
T_SRCDIR: ${{ format('{0}/tarantool-{1}', github.workspace, matrix.tarantool) }}
118+
T_TARDIR: ${{ format('{0}/tarantool-{1}-build', github.workspace, matrix.tarantool) }}
119+
SRCDIR: ${{ format('{0}/{1}', github.workspace, github.repository) }}
120+
121+
runs-on: ${{ matrix.runs-on }}
122+
steps:
123+
- name: Clone the connector
124+
uses: actions/checkout@v3
125+
with:
126+
path: ${{ env.SRCDIR }}
127+
128+
- name: Restore cache of tarantool ${{ env.T_VERSION }}
129+
uses: actions/cache@v3
130+
id: cache
131+
with:
132+
path: ${{ env.T_TARDIR }}
133+
key: ${{ matrix.runs-on }}-${{ matrix.tarantool }}
134+
if: matrix.tarantool != 'brew'
135+
136+
- name: Install latest tarantool from brew
137+
run: brew install tarantool
138+
if: matrix.tarantool == 'brew'
139+
140+
- name: Clone tarantool ${{ env.T_VERSION }}
141+
uses: actions/checkout@v3
142+
with:
143+
repository: tarantool/tarantool
144+
ref: ${{ env.T_VERSION }}
145+
path: ${{ env.T_TARDIR }}
146+
submodules: true
147+
# fetch-depth is 1 by default and it is okay for
148+
# building from a tag. However we have master in
149+
# the version list.
150+
fetch-depth: 0
151+
if: matrix.tarantool != 'brew' && steps.cache.outputs.cache-hit != 'true'
152+
153+
- name: Build tarantool ${{ env.T_VERSION }} from sources
154+
run: |
155+
cd "${T_TARDIR}"
156+
# Set RelWithDebInfo just to disable -Werror.
157+
#
158+
# There are tarantool releases on which AppleClang
159+
# complains about the problem that was fixed later in
160+
# https://github.com/tarantool/tarantool/commit/7e8688ff8885cc7813d12225e03694eb8886de29
161+
#
162+
# Set OpenSSL root directory for linking tarantool with OpenSSL of version 1.1
163+
# This is related to #49. There are too much deprecations which affect the build and tests.
164+
# Must be revisited after fixing https://github.com/tarantool/tarantool/issues/6477
165+
cmake . -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_DIST=ON -DOPENSSL_ROOT_DIR=/usr/local/opt/[email protected] -DOPENSSL_LIBRARIES=/usr/local/opt/[email protected]/lib
166+
# {{{ Workaround Mac OS build failure (gh-6076)
167+
#
168+
# https://github.com/tarantool/tarantool/issues/6076
169+
#
170+
# In brief: when "src/lib/small" is in include paths,
171+
# `#include <version>` from inside Mac OS SDK headers
172+
# attempts to include "src/lib/small/VERSION" as a
173+
# header file that leads to a syntax error.
174+
#
175+
# It was fixed in the following commits:
176+
#
177+
# * 1.10.10-24-g7bce4abd1
178+
# * 2.7.2-44-gbb1d32903
179+
# * 2.8.1-56-ga6c29c5af
180+
# * 2.9.0-84-gc5ae543f3
181+
#
182+
# However applying the workaround for all versions looks
183+
# harmless.
184+
#
185+
# Added -f just in case: I guess we'll drop this useless
186+
# obsoleted VERSION file from the git repository sooner
187+
# or later.
188+
rm -f src/lib/small/VERSION
189+
# The same as above, but for the VERSION file generated
190+
# by tarantool's CMake script.
191+
rm VERSION
192+
# }}} Workaround Mac OS build failure (gh-6076)
193+
# Continue the build.
194+
make -j$(sysctl -n hw.logicalcpu)
195+
make install
196+
if: matrix.tarantool != 'brew' && steps.cache.outputs.cache-hit != 'true'
197+
198+
- name: Install tarantool
199+
run: |
200+
cd "${T_TARDIR}"
201+
make install
202+
if: matrix.tarantool != 'brew' && steps.cache.outputs.cache-hit == 'true'
203+
204+
- name: Verify tarantool version
205+
run: |
206+
# Workaround https://github.com/tarantool/tarantool/issues/4983
207+
# Workaround https://github.com/tarantool/tarantool/issues/5040
208+
tarantool -e "require('fiber').sleep(0) assert(_TARANTOOL:startswith('${T_VERSION}'), _TARANTOOL) os.exit()"
209+
if: matrix.tarantool != 'brew' && matrix.tarantool != 'master'
210+
211+
- name: Setup golang for the connector and tests
212+
uses: actions/setup-go@v3
213+
with:
214+
go-version: ${{ matrix.golang }}
215+
216+
# Workaround for Mac OS 12 testrace failure
217+
# https://github.com/golang/go/issues/49138
218+
- name: disable MallocNanoZone for macos-12
219+
run: echo "MallocNanoZone=0" >> $GITHUB_ENV
220+
if: matrix.runs-on == 'macos-12'
221+
222+
# Workaround issue https://github.com/tarantool/tt/issues/640
223+
- name: Fix tt rocks
224+
if: matrix.tarantool == 'brew'
225+
run: |
226+
brew ls --verbose tarantool | grep macosx.lua | xargs rm -f
227+
228+
- name: Run regression tests
229+
run: go test -v -shuffle=on -coverprofile=module-coverage.txt -coverpkg=./... ./...

README.md

Whitespace-only changes.

connection.go

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package tlsdialer
2+
3+
import (
4+
"errors"
5+
"io"
6+
"net"
7+
8+
"github.com/tarantool/go-tarantool/v2"
9+
)
10+
11+
type tntConn struct {
12+
net net.Conn
13+
reader io.Reader
14+
writer writeFlusher
15+
}
16+
17+
// writeFlusher is the interface that groups the basic Write and Flush methods.
18+
type writeFlusher interface {
19+
io.Writer
20+
Flush() error
21+
}
22+
23+
// Addr makes tntConn satisfy the Conn interface.
24+
func (c *tntConn) Addr() net.Addr {
25+
return c.net.RemoteAddr()
26+
}
27+
28+
// Read makes tntConn satisfy the Conn interface.
29+
func (c *tntConn) Read(p []byte) (int, error) {
30+
return c.reader.Read(p)
31+
}
32+
33+
// Write makes tntConn satisfy the Conn interface.
34+
func (c *tntConn) Write(p []byte) (int, error) {
35+
if l, err := c.writer.Write(p); err != nil {
36+
return l, err
37+
} else if l != len(p) {
38+
return l, errors.New("wrong length written")
39+
} else {
40+
return l, nil
41+
}
42+
}
43+
44+
// Flush makes tntConn satisfy the Conn interface.
45+
func (c *tntConn) Flush() error {
46+
return c.writer.Flush()
47+
}
48+
49+
// Close makes tntConn satisfy the Conn interface.
50+
func (c *tntConn) Close() error {
51+
return c.net.Close()
52+
}
53+
54+
// Greeting makes tntConn satisfy the Conn interface.
55+
func (c *tntConn) Greeting() tarantool.Greeting {
56+
return tarantool.Greeting{}
57+
}
58+
59+
// ProtocolInfo makes tntConn satisfy the Conn interface.
60+
func (c *tntConn) ProtocolInfo() tarantool.ProtocolInfo {
61+
return tarantool.ProtocolInfo{}
62+
}

deadline_io.go

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package tlsdialer
2+
3+
import (
4+
"net"
5+
"time"
6+
)
7+
8+
type deadlineIO struct {
9+
to time.Duration
10+
c net.Conn
11+
}
12+
13+
func (d *deadlineIO) Write(b []byte) (n int, err error) {
14+
if d.to > 0 {
15+
d.c.SetWriteDeadline(time.Now().Add(d.to))
16+
}
17+
n, err = d.c.Write(b)
18+
return
19+
}
20+
21+
func (d *deadlineIO) Read(b []byte) (n int, err error) {
22+
if d.to > 0 {
23+
d.c.SetReadDeadline(time.Now().Add(d.to))
24+
}
25+
n, err = d.c.Read(b)
26+
return
27+
}

0 commit comments

Comments
 (0)