# Path: pycsp/parallel/protocol.py
# class ChannelMessenger(object):
# class LockMessenger(object):
# class RemoteLock(object):
# class Buffer(object):
# class ChannelHome(object):
# class AddrID(object):
# class ChannelReq(object):
# class ChannelHomeThread(threading.Thread):
#     def __init__(self):
#     def restore(self):
#     def register(self, channel):
#     def deregister(self, channel):
#     def join(self, channel, direction):
#     def retire(self, channel, direction):
#     def poison(self, channel, direction):
#     def post_read(self, channel, process, ack=False):
#     def post_write(self, channel, process, msg, ack=False):
#     def enter(self, channel, process):
#     def leave(self, channel, process):
#     def __init__(self, channel_id):
#     def set_reverse_socket(self, addr, reverse_socket):
#     def ack(self, dest):
#     def remote_acquire_and_get_state(self, dest):
#     def remote_notify(self, source_header, dest, result_ch, result_msg=b""):
#     def remote_poison(self, source_header, dest):
#     def remote_retire(self, source_header, dest):
#     def remote_release(self, source_header, dest):
#     def remote_final(self, dest):
#     def __init__(self, process):
#     def __repr__(self):
#     def handle(self, message):        
#     def __init__(self, LM, max):
#     def isfull(self):
#     def isempty(self):
#     def insertfrom(self, writer):
#     def putinto(self, reader):
#     def __init__(self, name, buffer):
#     def check_termination(self):
#     def post_read(self, req):
#     def post_write(self, req):
#     def leave(self, process_id):
#     def match(self):
#     def poison_reader(self):
#     def poison_writer(self):
#     def retire_reader(self):
#     def retire_writer(self):
#     def join_reader(self):
#     def join_writer(self):
#     def register(self):
#     def deregister(self):
#     def __init__(self, addr=(b"",0), id=b""):
#     def __init__(self, LM, process_src, process_seq, ch_id, msg = None):
#     def cancel(self):
#     def poison(self):
#     def retire(self):
#     def offer(self, reader):
#     def __init__(self, name, buffer, addr = None):
#     def run(self):
#         LM = self.channel.LM


import uuid
import pickle
from pycsp.parallel import protocol
from pycsp.parallel.exceptions import *
from pycsp.parallel.const import *
        if name == None:
            # Create 32 byte unique name based on network address, sequence number and time sample.
            self.name = uuid.uuid1().hex
        else:
            if len(name) > 32:
                raise Exception("Channel names are limited to 32 characters")

            self.name= name

        if type(self.name) != bytes:
            self.name = self.name.encode()

        self._CM = protocol.ChannelMessenger()

        # Set channel home
        self._channelhomethread = None

        if connect == None:

            try:

                # Check that the channel name is not already registered at this channel. If this is the
                # case, then throw exception.
                p,_ = getThreadAndName()

                for c in p.registeredChanHomeList:
                    if self.name == c.name:
                        raise InfoException("Reusing channel name in same process namespace")

                # Get local channel home

# Path: pycsp/parallel/protocol.py
# class ChannelMessenger(object):
# class LockMessenger(object):
# class RemoteLock(object):
# class Buffer(object):
# class ChannelHome(object):
# class AddrID(object):
# class ChannelReq(object):
# class ChannelHomeThread(threading.Thread):
#     def __init__(self):
#     def restore(self):
#     def register(self, channel):
#     def deregister(self, channel):
#     def join(self, channel, direction):
#     def retire(self, channel, direction):
#     def poison(self, channel, direction):
#     def post_read(self, channel, process, ack=False):
#     def post_write(self, channel, process, msg, ack=False):
#     def enter(self, channel, process):
#     def leave(self, channel, process):
#     def __init__(self, channel_id):
#     def set_reverse_socket(self, addr, reverse_socket):
#     def ack(self, dest):
#     def remote_acquire_and_get_state(self, dest):
#     def remote_notify(self, source_header, dest, result_ch, result_msg=b""):
#     def remote_poison(self, source_header, dest):
#     def remote_retire(self, source_header, dest):
#     def remote_release(self, source_header, dest):
#     def remote_final(self, dest):
#     def __init__(self, process):
#     def __repr__(self):
#     def handle(self, message):        
#     def __init__(self, LM, max):
#     def isfull(self):
#     def isempty(self):
#     def insertfrom(self, writer):
#     def putinto(self, reader):
#     def __init__(self, name, buffer):
#     def check_termination(self):
#     def post_read(self, req):
#     def post_write(self, req):
#     def leave(self, process_id):
#     def match(self):
#     def poison_reader(self):
#     def poison_writer(self):
#     def retire_reader(self):
#     def retire_writer(self):
#     def join_reader(self):
#     def join_writer(self):
#     def register(self):
#     def deregister(self):
#     def __init__(self, addr=(b"",0), id=b""):
#     def __init__(self, LM, process_src, process_seq, ch_id, msg = None):
#     def cancel(self):
#     def poison(self):
#     def retire(self):
#     def offer(self, reader):
#     def __init__(self, name, buffer, addr = None):
#     def run(self):
#         LM = self.channel.LM


# Path: pycsp/parallel/channel.py
import uuid
import pickle
from pycsp.parallel import protocol
from pycsp.parallel.exceptions import *
from pycsp.parallel.const import *

        if name == None:
            # Create 32 byte unique name based on network address, sequence number and time sample.
            self.name = uuid.uuid1().hex
        else:
            if len(name) > 32:
                raise Exception("Channel names are limited to 32 characters")

            self.name= name

        if type(self.name) != bytes:
            self.name = self.name.encode()

        self._CM = protocol.ChannelMessenger()

        # Set channel home
        self._channelhomethread = None

        if connect == None:

            try:

                # Check that the channel name is not already registered at this channel. If this is the
                # case, then throw exception.
                p,_ = getThreadAndName()

                for c in p.registeredChanHomeList:
                    if self.name == c.name:
                        raise InfoException("Reusing channel name in same process namespace")

                # Get local channel home

                self._channelhomethread = protocol.ChannelHomeThread(self.name, self.buffer)