Skip to content

Commit

Permalink
Cleanup repo structure and CI
Browse files Browse the repository at this point in the history
Changed repo structure to match other Pions repos.
Changed CI to match other Pions repos.
  • Loading branch information
backkem authored and Sean-Der committed Jan 23, 2019
1 parent da12df7 commit 78482ec
Show file tree
Hide file tree
Showing 90 changed files with 149 additions and 26 deletions.
45 changes: 45 additions & 0 deletions .github/assert-contributors.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash
set -e

# Unshallow the repo, this check doesn't work with this enabled
# https://github.com/travis-ci/travis-ci/issues/3412
if [ -f $(git rev-parse --git-dir)/shallow ]; then
git fetch --unshallow || true
fi

SCRIPT_PATH=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )

CONTRIBUTORS=()
EXCLUDED_CONTIBUTORS=('John R. Bradley')
MISSING_CONTIBUTORS=()

shouldBeIncluded () {
for i in "${EXCLUDED_CONTIBUTORS[@]}"
do
if [ "$i" == "$1" ] ; then
return 1
fi
done
return 0
}


IFS=$'\n' #Only split on newline
for contributor in $(git log --format='%aN' | sort -u)
do
if shouldBeIncluded $contributor; then
if ! grep -q "$contributor" "$SCRIPT_PATH/../README.md"; then
MISSING_CONTIBUTORS+=("$contributor")
fi
fi
done
unset IFS

if [ ${#MISSING_CONTIBUTORS[@]} -ne 0 ]; then
echo "Please add the following contributors to the README"
for i in "${MISSING_CONTIBUTORS[@]}"
do
echo "$i"
done
exit 1
fi
60 changes: 60 additions & 0 deletions .github/lint-commit-message.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env bash
set -e

display_commit_message_error() {
cat << EndOfMessage
$1
-------------------------------------------------
The preceding commit message is invalid
it failed '$2' of the following checks
* Separate subject from body with a blank line
* Limit the subject line to 50 characters
* Capitalize the subject line
* Do not end the subject line with a period
* Wrap the body at 72 characters
EndOfMessage

exit 1
}

lint_commit_message() {
if [[ "$(echo "$1" | awk 'NR == 2 {print $1;}' | wc -c)" -ne 1 ]]; then
display_commit_message_error "$1" 'Separate subject from body with a blank line'
fi

if [[ "$(echo "$1" | head -n1 | wc -m)" -gt 50 ]]; then
display_commit_message_error "$1" 'Limit the subject line to 50 characters'
fi

if [[ ! $1 =~ ^[A-Z] ]]; then
display_commit_message_error "$1" 'Capitalize the subject line'
fi

if [[ "$(echo "$1" | awk 'NR == 1 {print substr($0,length($0),1)}')" == "." ]]; then
display_commit_message_error "$1" 'Do not end the subject line with a period'
fi

if [[ "$(echo "$1" | awk '{print length}' | sort -nr | head -1)" -gt 72 ]]; then
display_commit_message_error "$1" 'Wrap the body at 72 characters'
fi
}

if [ "$#" -eq 1 ]; then
if [ ! -f "$1" ]; then
echo "$0 was passed one argument, but was not a valid file"
exit 1
fi
lint_commit_message "$(sed -n '/# Please enter the commit message for your changes. Lines starting/q;p' "$1")"
else
# TRAVIS_COMMIT_RANGE is empty for initial branch commit
if [[ "${TRAVIS_COMMIT_RANGE}" != *"..."* ]]; then
parent=$(git log -n 1 --format="%P" ${TRAVIS_COMMIT_RANGE})
TRAVIS_COMMIT_RANGE="${TRAVIS_COMMIT_RANGE}...$parent"
fi

for commit in $(git rev-list ${TRAVIS_COMMIT_RANGE}); do
lint_commit_message "$(git log --format="%B" -n 1 $commit)"
done
fi
2 changes: 1 addition & 1 deletion .github/lint-disallowed-functions-in-library.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -e

# Disallow usages of functions that cause the program to exit in the library code
SCRIPT_PATH=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
EXCLUDE_DIRECTORIES="--exclude-dir=cmd --exclude-dir=.git --exclude-dir=.github "
EXCLUDE_DIRECTORIES="--exclude-dir=examples --exclude-dir=.git --exclude-dir=.github "
DISALLOWED_FUNCTIONS=('os.Exit(' 'panic(' 'Fatal(' 'Fatalf(' 'Fatalln(')


Expand Down
13 changes: 10 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@ language: go
go:
- "1.x" # use the latest Go release

env:
- GO111MODULE=on

before_script:
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.12.3
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.13
- go get github.com/mattn/goveralls

script:
- golangci-lint run
- goveralls -v -race -covermode=atomic -service=travis-ci
- golangci-lint run ./...
- rm -rf examples # Remove examples, no test coverage for them
- go test -coverpkg=$(go list ./... | tr '\n' ',') -coverprofile=cover.out -v -race -covermode=atomic ./...
- goveralls -coverprofile=cover.out -service=travis-ci
- bash .github/assert-contributors.sh
- bash .github/lint-disallowed-functions-in-library.sh
- bash .github/lint-commit-message.sh
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ Pion DTLS can connect to itself and OpenSSL.
## Pion DTLS
For a DTLS 1.2 Server that listens on 127.0.0.1:4444
```sh
go run cmd/listen/main.go
go run examples/listen/main.go
```

For a DTLS 1.2 Client that connects to 127.0.0.1:4444
```sh
go run cmd/dial/main.go
go run examples/dial/main.go
```

## OpenSSL
Expand All @@ -65,10 +65,10 @@ go run cmd/dial/main.go
openssl req -new -sha256 -key key.pem -out server.csr
openssl x509 -req -sha256 -days 365 -in server.csr -signkey key.pem -out cert.pem
// Use with cmd/dial/main.go
// Use with examples/dial/main.go
openssl s_server -dtls1_2 -cert cert.pem -key key.pem -accept 4444
// Use with cmd/listen/main.go
// Use with examples/listen/main.go
openssl s_client -dtls1_2 -connect 127.0.0.1:4444 -debug -cert cert.pem -key key.pem
```

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions e2e/e2e.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package e2e contains end to end tests for pions/dtls
package e2e
4 changes: 2 additions & 2 deletions test/e2e/pion/simple_test.go → e2e/e2e_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pion
package e2e

import (
"io"
Expand All @@ -10,7 +10,7 @@ import (
"testing"
"time"

"github.com/pions/dtls/pkg/dtls"
"github.com/pions/dtls"
)

const testMessage = "Hello World"
Expand Down
File renamed without changes.
12 changes: 6 additions & 6 deletions cmd/dial/main.go → examples/dial/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"net"

"github.com/pions/dtls/cmd"
"github.com/pions/dtls/pkg/dtls"
"github.com/pions/dtls"
"github.com/pions/dtls/examples/util"
)

func main() {
Expand All @@ -14,7 +14,7 @@ func main() {

// Generate a certificate and private key to secure the connection
certificate, privateKey, genErr := dtls.GenerateSelfSigned()
cmd.Check(genErr)
util.Check(genErr)

//
// Everything below is the pion-DTLS API! Thanks for using it ❤️.
Expand All @@ -25,13 +25,13 @@ func main() {

// Connect to a DTLS server
dtlsConn, err := dtls.Dial("udp", addr, config)
cmd.Check(err)
util.Check(err)
defer func() {
cmd.Check(dtlsConn.Close())
util.Check(dtlsConn.Close())
}()

fmt.Println("Connected; type 'exit' to shutdown gracefully")

// Simulate a chat session
cmd.Chat(dtlsConn)
util.Chat(dtlsConn)
}
14 changes: 7 additions & 7 deletions cmd/listen/main.go → examples/listen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"strings"
"sync"

"github.com/pions/dtls/cmd"
"github.com/pions/dtls/pkg/dtls"
"github.com/pions/dtls"
"github.com/pions/dtls/examples/util"
)

func main() {
Expand All @@ -18,7 +18,7 @@ func main() {

// Generate a certificate and private key to secure the connection
certificate, privateKey, genErr := dtls.GenerateSelfSigned()
cmd.Check(genErr)
util.Check(genErr)

//
// Everything below is the pion-DTLS API! Thanks for using it ❤️.
Expand All @@ -29,9 +29,9 @@ func main() {

// Connect to a DTLS server
listener, err := dtls.Listen("udp", addr, config)
cmd.Check(err)
util.Check(err)
defer func() {
cmd.Check(listener.Close())
util.Check(listener.Close())
}()

fmt.Println("Listening")
Expand All @@ -43,7 +43,7 @@ func main() {
for {
// Wait for a connection.
conn, err := listener.Accept()
cmd.Check(err)
util.Check(err)
// defer conn.Close() // TODO: graceful shutdown

// Register the connection with the chat hub
Expand Down Expand Up @@ -116,7 +116,7 @@ func (h *hub) chat() {
reader := bufio.NewReader(os.Stdin)
for {
msg, err := reader.ReadString('\n')
cmd.Check(err)
util.Check(err)
if strings.TrimSpace(msg) == "exit" {
return
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/util.go → examples/util/util.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package util

import (
"bufio"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module github.com/pions/dtls

require (
github.com/pions/transport v0.1.0
golang.org/x/crypto v0.0.0-20190123085648-057139ce5d2b
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
github.com/pions/transport v0.1.0 h1:9IEn3i8pmK8rMyQIqhT2RozgXJNH4k+IuNDzV5y+ddw=
github.com/pions/transport v0.1.0/go.mod h1:HLhzI7I0k8TyiQ99hfRZNRf84lG76eaFnZHnVy/wFnM=
golang.org/x/crypto v0.0.0-20190123085648-057139ce5d2b h1:Elez2XeF2p9uyVj0yEUDqQ56NFcDtcBNkYP7yv8YbUE=
golang.org/x/crypto v0.0.0-20190123085648-057139ce5d2b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion pkg/dtls/listener.go → listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"net"

"github.com/pions/dtls/pkg/dtls/internal/udp"
"github.com/pions/dtls/internal/udp"
)

// Listen creates a DTLS listener
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion test/e2e/pion/pion.go

This file was deleted.

File renamed without changes.

0 comments on commit 78482ec

Please sign in to comment.