Compare commits
17 Commits
b61c5862cc
...
kd-live
| Author | SHA1 | Date | |
|---|---|---|---|
| c31f838ba8 | |||
| f9a146321c | |||
| ea8ae4d02c | |||
| 8173216e95 | |||
| f4510f8990 | |||
| ead6543d95 | |||
| 38683eb616 | |||
| dd05ebf6ce | |||
| b759f13eee | |||
| 3024a17b54 | |||
| a9de99b04a | |||
| 65d3081870 | |||
| 8b74f50a1d | |||
| fcdf1642d2 | |||
| ed6ebc2761 | |||
| 262b9cadec | |||
| 0c11e4bc13 |
@ -299,8 +299,6 @@ func (sc *AuthCollection) RemoveByAccId(accid primitive.ObjectID) {
|
|||||||
sc.lock.Lock()
|
sc.lock.Lock()
|
||||||
defer sc.lock.Unlock()
|
defer sc.lock.Unlock()
|
||||||
|
|
||||||
logger.Println("AuthCollection.RemoveByAccId :", accid.Hex())
|
|
||||||
|
|
||||||
var sk string
|
var sk string
|
||||||
if on, ok := sc.reverseOn[accid]; ok {
|
if on, ok := sc.reverseOn[accid]; ok {
|
||||||
sk = on
|
sk = on
|
||||||
@ -326,8 +324,6 @@ func (sc *AuthCollection) RemoveBySessionKey(sk string, publish bool) (accid pri
|
|||||||
sc.lock.Lock()
|
sc.lock.Lock()
|
||||||
defer sc.lock.Unlock()
|
defer sc.lock.Unlock()
|
||||||
|
|
||||||
logger.Println("AuthCollection.RemoveBySessionKey :", sk, publish)
|
|
||||||
|
|
||||||
if publish {
|
if publish {
|
||||||
// 나한테 있든 없든 무조건 publish해야 함
|
// 나한테 있든 없든 무조건 publish해야 함
|
||||||
sc.SessionRemoved(sk)
|
sc.SessionRemoved(sk)
|
||||||
|
|||||||
59
coupon/helper.go
Normal file
59
coupon/helper.go
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
package coupon
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/md5"
|
||||||
|
"encoding/binary"
|
||||||
|
"encoding/hex"
|
||||||
|
"math/rand"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func DisolveCouponCode(code string) (round string, key string) {
|
||||||
|
var final []byte
|
||||||
|
for _, n := range strings.Split(code, "-") {
|
||||||
|
nb, err := hex.DecodeString(n)
|
||||||
|
if err != nil {
|
||||||
|
// 형식 오류
|
||||||
|
return "", ""
|
||||||
|
}
|
||||||
|
final = append(final, nb...)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(final) != 8 {
|
||||||
|
// 형식 오류
|
||||||
|
return "", ""
|
||||||
|
}
|
||||||
|
|
||||||
|
uid := final[4:]
|
||||||
|
left := binary.BigEndian.Uint16(uid[0:2])
|
||||||
|
right := binary.BigEndian.Uint16(uid[2:4])
|
||||||
|
|
||||||
|
final = final[0:4]
|
||||||
|
xor := binary.LittleEndian.Uint32(final)
|
||||||
|
roundhashnum := xor ^ (uint32(left) * uint32(right))
|
||||||
|
|
||||||
|
roundhash := make([]byte, 4)
|
||||||
|
binary.BigEndian.PutUint32(roundhash, roundhashnum)
|
||||||
|
|
||||||
|
round = hex.EncodeToString(roundhash)
|
||||||
|
key = hex.EncodeToString(uid)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func MakeCouponRoundHash(name string) (hash string, roundNumber uint32) {
|
||||||
|
m5 := md5.New()
|
||||||
|
m5.Write([]byte(name))
|
||||||
|
hashbt := m5.Sum(nil)
|
||||||
|
|
||||||
|
roundbt := make([]byte, 8)
|
||||||
|
copy(roundbt, hashbt[:8])
|
||||||
|
|
||||||
|
roundseed := int64(binary.BigEndian.Uint64(roundbt))
|
||||||
|
roundhash := make([]byte, 4)
|
||||||
|
rand.New(rand.NewSource(roundseed)).Read(roundhash)
|
||||||
|
roundNumber = binary.BigEndian.Uint32(roundhash)
|
||||||
|
hash = hex.EncodeToString(roundhash)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
69
server.go
69
server.go
@ -73,6 +73,7 @@ func healthCheckHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// 한번이라도 들어오면 lb에 붙어있다는 뜻
|
// 한번이라도 들어오면 lb에 붙어있다는 뜻
|
||||||
if t := atomic.AddInt64(&healthcheckcounter, 1); t < 0 {
|
if t := atomic.AddInt64(&healthcheckcounter, 1); t < 0 {
|
||||||
|
logger.Println("healthCheckHandler return StatusServiceUnavailable :", t)
|
||||||
w.WriteHeader(http.StatusServiceUnavailable)
|
w.WriteHeader(http.StatusServiceUnavailable)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -127,11 +128,25 @@ func (server *Server) shutdown() {
|
|||||||
|
|
||||||
signal.Stop(server.interrupt)
|
signal.Stop(server.interrupt)
|
||||||
|
|
||||||
if atomic.LoadInt64(&healthcheckcounter) > 0 {
|
if t := atomic.LoadInt64(&healthcheckcounter); t > 0 {
|
||||||
|
logger.Println("http server shutdown. healthcheckcounter :", t)
|
||||||
atomic.StoreInt64(&healthcheckcounter, math.MinInt64)
|
atomic.StoreInt64(&healthcheckcounter, math.MinInt64)
|
||||||
for atomic.LoadInt64(&healthcheckcounter)-math.MinInt64 > 10 {
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
timer := 600 // 0.1 * 600 = 1분
|
||||||
|
for cnt := 0; cnt < 100 && timer > 0; {
|
||||||
|
next := atomic.LoadInt64(&healthcheckcounter)
|
||||||
|
if next == t {
|
||||||
|
cnt++
|
||||||
|
} else {
|
||||||
|
t = next
|
||||||
|
cnt = 0
|
||||||
}
|
}
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
timer--
|
||||||
|
}
|
||||||
|
logger.Println("http server shutdown. healthcheck completed")
|
||||||
|
} else {
|
||||||
|
logger.Println("http server shutdown. no lb")
|
||||||
}
|
}
|
||||||
|
|
||||||
if server.httpserver != nil {
|
if server.httpserver != nil {
|
||||||
@ -536,3 +551,51 @@ func MakeRPCError() *RpcReturnError {
|
|||||||
h: nil,
|
h: nil,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type indirectBody struct {
|
||||||
|
inner io.ReadCloser
|
||||||
|
dump []byte
|
||||||
|
closer func()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ib *indirectBody) Read(p []byte) (n int, err error) {
|
||||||
|
n, err = ib.inner.Read(p)
|
||||||
|
if n > 0 {
|
||||||
|
ib.dump = append(ib.dump, p...)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ib *indirectBody) Close() error {
|
||||||
|
if ib.closer != nil {
|
||||||
|
ib.closer()
|
||||||
|
ib.closer = nil
|
||||||
|
}
|
||||||
|
return ib.inner.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
func MakeHttpRequestForLogging(r *http.Request) *http.Request {
|
||||||
|
ib := &indirectBody{
|
||||||
|
inner: r.Body,
|
||||||
|
}
|
||||||
|
|
||||||
|
closer := func() {
|
||||||
|
var uv url.Values
|
||||||
|
|
||||||
|
if r.Form != nil {
|
||||||
|
uv = r.Form
|
||||||
|
} else {
|
||||||
|
uv = r.URL.Query()
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Println("request :")
|
||||||
|
logger.Println(" header :", r.Header)
|
||||||
|
logger.Println(" values :", uv)
|
||||||
|
logger.Println(" body :", string(ib.dump))
|
||||||
|
}
|
||||||
|
|
||||||
|
ib.closer = closer
|
||||||
|
|
||||||
|
r.Body = ib
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user