<commit_before>package network

import (
    "fmt"
    "net"
    "encoding/binary"

    pb "code.google.com/p/goprotobuf/proto"

    "sal/proto"
)

const (
    URI_REGISTER        = 1
    URI_TRANSPORT       = 2
    URI_UNREGISTER      = 3
    LEN_URI             = 4
    FRONT_PORT          = ":3929"
)


type SalFrontend struct {
    buffChan        chan *ConnBuff
    sid2conn        map[uint32]*ClientConnection
    conn2sid        map[*ClientConnection]uint32
    SalEntry        chan *proto.SalPack
    SalExit         chan *proto.SalPack
}

func NewSalFrontend(entry, exit chan *proto.SalPack) *SalFrontend {
    gs := &SalFrontend{buffChan: make(chan *ConnBuff),
                    sid2conn: make(map[uint32]*ClientConnection),
                    conn2sid: make(map[*ClientConnection]uint32),
                    SalEntry: entry,
                    SalExit:  exit}
    go gs.parse()
    return gs
}


func (this *SalFrontend) Start() {
    ln, err := net.Listen("tcp", FRONT_PORT)                                                                            
    if err != nil {
        fmt.Println("Listen err", err)
        return
    }
    fmt.Println("SalFrontend running", FRONT_PORT)
    for {
        conn, err := ln.Accept()
        if err != nil {
            fmt.Println("Accept error", err)
            continue
        }
        go this.acceptConn(conn)
    }
}

func (this *SalFrontend) acceptConn(conn net.Conn) {
    cliConn := NewClientConnection(conn)
    for {
        if buff_body, ok := cliConn.duplexReadBody(); ok {
            this.buffChan <- &ConnBuff{cliConn, buff_body}
            continue
        }
        this.buffChan <- &ConnBuff{cliConn, nil}
        break
    }
}

func (this *SalFrontend) parse() {
    for {
        select {
            case conn_buff := <-this.buffChan :
                msg := conn_buff.buff
                conn := conn_buff.conn

                if msg == nil {
                    this.unregister(conn)
                    continue
                }

                uri := binary.LittleEndian.Uint32(msg[:LEN_URI])
                switch uri {
                case URI_REGISTER:
                    this.register(msg[LEN_URI:], conn)
                case URI_TRANSPORT:
                    this.comein(msg[LEN_URI:])
                default:
                    this.unregister(conn)
                }

            case pack := <-this.SalExit :
                this.comeout(pack)
        }
    }
}
<commit_msg>connect info<commit_after>package network

import (
    "fmt"
    "net"
    "encoding/binary"

    pb "code.google.com/p/goprotobuf/proto"

    "sal/proto"
)

const (
    URI_REGISTER        = 1
    URI_TRANSPORT       = 2
    URI_UNREGISTER      = 3
    LEN_URI             = 4
    FRONT_PORT          = ":3929"
)


type SalFrontend struct {
    buffChan        chan *ConnBuff
    sid2conn        map[uint32]*ClientConnection
    conn2sid        map[*ClientConnection]uint32
    SalEntry        chan *proto.SalPack
    SalExit         chan *proto.SalPack
}

func NewSalFrontend(entry, exit chan *proto.SalPack) *SalFrontend {
    gs := &SalFrontend{buffChan: make(chan *ConnBuff),
                    sid2conn: make(map[uint32]*ClientConnection),
                    conn2sid: make(map[*ClientConnection]uint32),
                    SalEntry: entry,
                    SalExit:  exit}
    go gs.parse()
    return gs
}


func (this *SalFrontend) Start() {
    ln, err := net.Listen("tcp", FRONT_PORT)                                                                            
    if err != nil {
        fmt.Println("Listen err", err)
        return
    }
    fmt.Println("SalFrontend running", FRONT_PORT)
    for {
        conn, err := ln.Accept()
        if err != nil {
            fmt.Println("Accept error", err)
            continue
        }
        fmt.Println("sal agent connected")
        go this.acceptConn(conn)
    }
}

func (this *SalFrontend) acceptConn(conn net.Conn) {
    cliConn := NewClientConnection(conn)
    for {
        if buff_body, ok := cliConn.duplexReadBody(); ok {
            this.buffChan <- &ConnBuff{cliConn, buff_body}
            continue
        }
        this.buffChan <- &ConnBuff{cliConn, nil}
        break
    }
    fmt.Println("sal agent disconnect")
}

func (this *SalFrontend) parse() {
    for {
        select {
            case conn_buff := <-this.buffChan :
                msg := conn_buff.buff
                conn := conn_buff.conn

                if msg == nil {
                    this.unregister(conn)
                    continue
                }

                uri := binary.LittleEndian.Uint32(msg[:LEN_URI])
                switch uri {
                case URI_REGISTER:
                    this.register(msg[LEN_URI:], conn)
                case URI_TRANSPORT:
                    this.comein(msg[LEN_URI:])
                default:
                    this.unregister(conn)
                }

            case pack := <-this.SalExit :
                this.comeout(pack)
        }
    }
}

{'fraction_non_alphanumeric': 0.09801587301587301, 'fraction_numerical': 0.00873015873015873, 'mean_word_length': 1.395912547528517, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6476039', 'n_tokens_mistral': 1547, 'n_tokens_neox': 1427, 'n_words': 297}